qqzsxyz / vimwiki

Automatically exported from code.google.com/p/vimwiki
0 stars 0 forks source link

Markdown: unable to convert wikiwords to HTML #351

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
*What steps will reproduce the problem?*
1. set `wiki syntax` to markdown
2. set `custom_wiki2html` to a conversion script
3. define a bunch of wikilinks as `[[WikiWords]]`
4. convert the wiki to HTML

*What is the expected output? What do you see instead?*
I would like to see the WikiWords turning into HTML links, but they don't. 
They're converted as body text, so the HTML output shows them as 
`[[WikiWords]]`.

*What version of the product are you using? On what operating system?*
Version 2.0.1 'stu' on Windows XP.

*Please provide any additional information below.*
This is currently not documented in the helpfile: Markdown doesn't (AFAIK) 
support WikiLinks, but is there a workaround for this? How do you, 
VimwikiMarkdownUsers, define your WikiLinks inside Vim? Is 
`[WikiWord](WikiWord.html)` the only option?

Thanks!

Original issue reported on code.google.com by martzirn...@gmail.com on 19 Jul 2012 at 4:27

GoogleCodeExporter commented 8 years ago
Depending on the custom markdown converter, you might not need to do anything.

Otherwise, you can simulate `[[Wikilinks]]` using markdown reference-style 
links.  To accomplish this, you need to do 3 things.

 1. Make sure that the `[[Wikilinks]]` are in a reference-style format recognized by your chosen markdown converter, for example, by transforming each occurance of a `[[Wikilink]]` into (a) `[Wikilink]`, (b) `[Wikilink][]`, or (c) `[Wikilink][Wikilink]`.  With markdown as the chosen syntax, you can simply type "+" with the cursor above the link to cycle between syntaxes.

 2. Create a reference-style index of all of your wiki files, with suitable html target, e.g. `[Wikilink]: file:///path_html/Wikilink.html`.  The following "make-index.sh" script does this in the constrained setting where all my pages are located at the root level.  The input directory is the same as the wiki's path, and the output directory is the same as path_html.  You will likely need to adjust the filtering performed by the recurring "grep -v" commands.

 3. Concatenate the index file to the end of each markdown source file that is passed to your custom_wiki2html wrapper.  In this way, for each `Wikilink` encountered, the converter will be able to retrieve the target address from the index.

HTH,
- S.

``` bash
  # usage: make-index.sh <input-directory> <output-directory>
  INPUTDIR=$1
  OUTPUTDIR=$2

  INDEX=$OUTPUTDIR/MkdIndex.md

  # create new blank index
  echo "" >| "$INDEX"
  echo "" >> "$INDEX"

  # get note names and reformat as markdown reformat links
  #    n.b. fwd-slash after DIR in case it is a link
  find "$INPUTDIR/" -name "*[^\~]" -type "f"        | \
      grep -v "\.DS_Store"                               | \
      grep -v "\..*.swp"                                 | \
      grep -v ".hg\/"                                    | \
      grep -v ".hgignore"                                | \
      perl -p -e 's#.md$##'                             | \
      perl -p -e "s#^$INPUTDIR/*##"                 | \
      perl -p -e 's#^(.*)$#\[${1}\]: XX-XX-XX/${1}.html#' | \
      perl -p -e "s#XX-XX-XX#file://$OUTPUTDIR#"    >> "$INDEX"

Original comment by `stu.andrews` on 20 Jul 2012 at 5:33
GoogleCodeExporter commented 8 years ago
Thanks for the quick explanation, Stu!

I did not know about the cycling with "+" (for I had always pressed it only 
once to generate the links :-) This is very handy, I think it should be pointed 
out in the helpfile as well.

I'm converting with Pandoc, which defines links as `[Wikilink](Wikilink.html)`. 
I'll modify my ´vimwiki_markdown.vim´ accordingly to have them included in 
the "+ cycle".

However -- can you name any markdown converters that define wikilinks as 
[[Wikilink]]?

I haven't googled out any so far. I did try Discount (which, I guess, you 
proposed somewhere) but that did not do the trick for me, at least not in WinXP 
+ MinGW.

Thanks again!
M.

Original comment by martzirn...@gmail.com on 20 Jul 2012 at 12:11

GoogleCodeExporter commented 8 years ago
Re: my own question about Markdown converters reading [[Wikilinks]]:

Great news, Markdown for Python can do this:
http://freewisdom.org/projects/python-markdown/
http://freewisdom.org/projects/python-markdown/WikiLinks

And, as for all the other plugins, it appears to be an awesome tool! Had it 
Pandoc's `[@academic-references]` support as well, I'd be sold entirely.

Cheers,
M.

Original comment by martzirn...@gmail.com on 20 Jul 2012 at 1:15

GoogleCodeExporter commented 8 years ago

Original comment by stu.andrews on 26 Jul 2012 at 9:39