public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Will there ever be a standard wiki-link?
Date: Sat, 24 Aug 2019 12:06:48 +0200	[thread overview]
Message-ID: <93baab2f-5229-5985-2332-aa503eee0b95@gmail.com> (raw)
In-Reply-To: <e7323376-2751-e4b4-4d74-14c966bb884a-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1235 bytes --]

On 2019-08-21 18:08, Joseph Reagle wrote:
> I'm noticing folks building wikis using markdown increasingly adopting the convention [[local link]]. However, gitit uses [local link](). Any chance one of these will be standardized or adopted by Pandoc?
> 


The attached Lua filter kind of does the trick if you want to generate 
Markdown e.g. for GitHub wikis. It converts three different "syntaxes"
into wiki link syntax:

   Get [[...]] style wiki links in Pandoc Markdown output:

   [PAGE NAME]() becomes [[PAGE NAME]]   (Formatting is lost)

   [FORMATTED TEXT]{wiki="PAGE NAME"}
       becomes [[PAGE NAME|FORMATTED TEXT]]

   `TEXT`{.wiki} becomes [[TEXT]]        (Very fast!)

       $ pandoc --lua-filter wiki-links.lua -w gfm
       [foo]() [*bar*]{wiki="baz"} `quux`{.wiki}
       ^D
       [[foo]] [[baz|*bar*]] [[quux]]



-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/93baab2f-5229-5985-2332-aa503eee0b95%40gmail.com.

[-- Attachment #2: wiki-links.lua --]
[-- Type: text/x-lua, Size: 2947 bytes --]

--[=====================================================================[

  Get [[...]] style wiki links in Pandoc Markdown output:
  
  [PAGE NAME]() becomes [[PAGE NAME]]   (Formatting is lost)
  
  [FORMATTED TEXT]{wiki="PAGE NAME"} becomes [[PAGE NAME|FORMATTED TEXT]]
  
  `TEXT`{.wiki} becomes [[TEXT]]        (Very fast!)

      $ pandoc --lua-filter wiki-links.lua -w gfm
      [foo]() [*bar*]{wiki="baz"} `quux`{.wiki}
      ^D
      [[foo]] [[baz|*bar*]] [[quux]]

--]=====================================================================]

local wiki_class = "wiki" -- feel free to change this to e.g. "w"

function Link (elem)
  if "" == elem.target then
    local text = pandoc.utils.stringify(elem)
    return {
      pandoc.RawInline('markdown', '[[' .. text .. ']]' )
    }
  end
  return nil
end

function Code (elem)
  if elem.classes:includes(wiki_class) then
    return { pandoc.RawInline('markdown', '[[' .. elem.text .. ']]') }
  end
  return nil
end

function Span (elem)
  local wiki = elem.attributes[wiki_class]
  if wiki then
    -- construct the part before the formatted text
    prefix  = pandoc.RawInline('markdown', '[[' .. wiki .. '|')
    -- the part after the formatted text
    suffix = pandoc.RawInline('markdown', ']]')
    -- the formatted text == the span content
    local content = elem.content
    -- prepend the prefix
    table.insert(content, 1, prefix)
    -- append the suffix most efficiently
    content[#content+1] = suffix
    return content
  end
  return nil
end



--[=====================================================================[

  This software is Copyright (c) 2019 by Benct Philip Jonsson.
  
  This is free software, licensed under:
  
    The MIT (X11) License
  
  The MIT License
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated
  documentation files (the "Software"), to deal in the Software
  without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to
  whom the Software is furnished to do so, subject to the
  following conditions:
  
  The above copyright notice and this permission notice shall
  be included in all copies or substantial portions of the
  Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT
  WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR
  PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.

--]=====================================================================]

-- Vim: set ft=lua sw=2 sts=2 et fdm=indent:

      parent reply	other threads:[~2019-08-24 10:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21 16:08 Joseph Reagle
     [not found] ` <e7323376-2751-e4b4-4d74-14c966bb884a-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2019-08-23  9:44   ` mb21
     [not found]     ` <9cbec34f-8bca-429f-8cf9-954dbeeb6a87-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-08-23 13:19       ` Joseph Reagle
     [not found]         ` <db2b6987-1e92-1e0a-6b29-d2b7265ab1cf-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2019-08-23 17:14           ` John MacFarlane
     [not found]             ` <m2lfvjhkia.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-08-23 18:17               ` Joseph Reagle
     [not found]                 ` <d8b31c74-f60f-23a8-afc7-3cd2a76924c0-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2019-08-23 19:17                   ` John MacFarlane
     [not found]                     ` <yh480kmufzbsju.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-08-23 22:02                       ` Kolen Cheung
2019-08-29 12:32       ` Joseph Reagle
2019-08-24 10:06   ` BPJ [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=93baab2f-5229-5985-2332-aa503eee0b95@gmail.com \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).