* Output-Format Plain removes Markdown-Hyperlinks []()
@ 2022-01-14 11:20 Peter Mueller
[not found] ` <f3cf23c8-71a0-4825-812d-652b8d1ccc71n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Peter Mueller @ 2022-01-14 11:20 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1163 bytes --]
Hello together.
I'm working on a project where we use one input markdown file to create
HTML but also TXT files.
The problem I have is with markdown hyperlinks in the form of []().
While for the output format html they are kept:
*$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
markdown -t html*
*<p>prefix <a href="www.google.de">this is a link</a> suffix</p>*
the url is completely removed for plain output:
*$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
markdown -t plain*
*prefix this is a link suffix*
Is there a way/plugin to keep the url within the plain output?
(e.g. by keeping the markdown [this is a link](www.google.de) as it is,
but handling all other markdown as usual?)
Thank you
Peter
--
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/f3cf23c8-71a0-4825-812d-652b8d1ccc71n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1675 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Output-Format Plain removes Markdown-Hyperlinks []()
[not found] ` <f3cf23c8-71a0-4825-812d-652b8d1ccc71n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-01-15 14:41 ` BPJ
[not found] ` <c26e9460-27b6-ed81-2701-e1f3dcbac293-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: BPJ @ 2022-01-15 14:41 UTC (permalink / raw)
To: pandoc-discuss
Here with pandoc 2.16.2 `[TEXT](URL)` is automatically turned into `TEXT
<URL>` in plain output, being smart enough to do the right thing if the
URL appears in the link text or if it was `<URL>` already.
Anyway attached is a Lua filter which I use to get the same effect in
other output formats. Unless you are running a very old version of
pandoc it should do what you want unless pandoc does it already.
On 2022-01-14 12:20, Peter Mueller wrote:
> Hello together.
>
> I'm working on a project where we use one input markdown file to create
> HTML but also TXT files.
> The problem I have is with markdown hyperlinks in the form of []().
>
> While for the output format html they are kept:
> *$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
> markdown -t html*
> *<p>prefix <a href="www.google.de">this is a link</a> suffix</p>*
>
> the url is completely removed for plain output:
> *$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
> markdown -t plain*
> *prefix this is a link suffix*
>
> Is there a way/plugin to keep the url within the plain output?
> (e.g. by keeping the markdown [this is a link](www.google.de) as it is,
> but handling all other markdown as usual?)
>
> Thank you
> Peter
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Output-Format Plain removes Markdown-Hyperlinks []()
[not found] ` <c26e9460-27b6-ed81-2701-e1f3dcbac293-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-01-15 14:44 ` BPJ
0 siblings, 0 replies; 3+ messages in thread
From: BPJ @ 2022-01-15 14:44 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 1813 bytes --]
Ack I forgot the attachments! Typical... :-)
On 2022-01-15 15:41, BPJ wrote:
> Here with pandoc 2.16.2 `[TEXT](URL)` is automatically turned into `TEXT
> <URL>` in plain output, being smart enough to do the right thing if the
> URL appears in the link text or if it was `<URL>` already.
>
> Anyway attached is a Lua filter which I use to get the same effect in
> other output formats. Unless you are running a very old version of
> pandoc it should do what you want unless pandoc does it already.
>
> On 2022-01-14 12:20, Peter Mueller wrote:
>> Hello together.
>>
>> I'm working on a project where we use one input markdown file to create
>> HTML but also TXT files.
>> The problem I have is with markdown hyperlinks in the form of []().
>>
>> While for the output format html they are kept:
>> *$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
>> markdown -t html*
>> *<p>prefix <a href="www.google.de">this is a link</a> suffix</p>*
>>
>> the url is completely removed for plain output:
>> *$ echo "prefix [this is a link](www.google.de) suffix" | pandoc -f
>> markdown -t plain*
>> *prefix this is a link suffix*
>>
>> Is there a way/plugin to keep the url within the plain output?
>> (e.g. by keeping the markdown [this is a link](www.google.de) as it is,
>> but handling all other markdown as usual?)
>>
>> Thank you
>> Peter
>>
>
--
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/90b5b9c0-3597-372e-5436-99a6f0c41d2f%40gmail.com.
[-- Attachment #2: result.html --]
[-- Type: text/html, Size: 293 bytes --]
[-- Attachment #3: plain-links.lua --]
[-- Type: text/x-lua, Size: 1652 bytes --]
-- Pandoc filter which turns `[TEXT](URL)` into `TEXT \<URL>`
-- Save some typing and sidewise space! :-)
local p = assert(pandoc, "Cannot find pandoc library")
local u = assert(p.utils, "Cannot find pandoc.utils library")
-- Classes which Pandoc inserts into links with URL/email as link text
local plain_classes = { 'uri', 'email' }
-- Get a nice-looking URL/email string
local function bare_url (url)
-- Remove wrapping angles just in case
url = tostring(url):gsub("^%<", "")
url = url:gsub("%>$", "")
-- Remove the mailto protocol if any
url = url:gsub("^mailto%:", "")
return url
end
-- Get a pattern which matches a string literally
-- by escaping all punctuation chars in the string
local function quote_pat (str)
return tostring(str):gsub('%p', '%%%0')
end
-- The main action
function Link (link)
-- Get the link text as a list of inlines
local ct = link.content
local url = link.target
-- Return just the link text if the link is local
if url:match('^%#') then
return ct
end
-- Get the link text as a string (without formatting)
local txt = u.stringify(link)
-- See if we got one of Pandoc's automatic classes
for _, cls in ipairs(plain_classes) do
if link.classes:includes(cls) then
-- If yes return just `<URL>` or `<EMAIL>`
return p.Str("<" .. tostring(bare_url(txt)) .. ">")
end
end
-- Else if the link text contains the URL/email
-- return just the link text
if txt:match(quote_pat(bare_url(url))) then
return ct
end
-- Else append `<URL>` or `<EMAIL>` to the link text
ct:extend({ p.Space(), p.Str("<" .. tostring(bare_url(url)) .. ">") })
return ct
end
[-- Attachment #4: result.md --]
[-- Type: text/markdown, Size: 234 bytes --]
Go to our site \<http://example.org>.
You can find us at http://example.org.
Go to our site at \<http://example.org>.
Drop us a mail \<info\@example.org>.
Send a mail to \<info\@example.org>.
Send a mail to \<info\@example.org>.
[-- Attachment #5: result.txt --]
[-- Type: text/plain, Size: 226 bytes --]
Go to our site <http://example.org>.
You can find us at http://example.org.
Go to our site at <http://example.org>.
Drop us a mail <info@example.org>.
Send a mail to <info@example.org>.
Send a mail to <info@example.org>.
[-- Attachment #6: test.md --]
[-- Type: text/markdown, Size: 397 bytes --]
Go to [our site](http://example.org).
[You can find us at http://example.org](http://example.org).
Go to our site at <http://example.org>.
Drop us a [mail](mailto:info-hcDgGtZH8xNAfugRpC6u6w@public.gmane.org).
Send a mail to <info-hcDgGtZH8xNAfugRpC6u6w@public.gmane.org>.
[Send a mail to <info-hcDgGtZH8xNAfugRpC6u6w@public.gmane.org>](mailto:info-hcDgGtZH8xNAfugRpC6u6w@public.gmane.org).
[-- Attachment #7: unfiltered-plain.txt --]
[-- Type: text/plain, Size: 226 bytes --]
Go to our site <http://example.org>.
You can find us at http://example.org.
Go to our site at <http://example.org>.
Drop us a mail <info@example.org>.
Send a mail to <info@example.org>.
Send a mail to <info@example.org>.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-01-15 14:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 11:20 Output-Format Plain removes Markdown-Hyperlinks []() Peter Mueller
[not found] ` <f3cf23c8-71a0-4825-812d-652b8d1ccc71n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-01-15 14:41 ` BPJ
[not found] ` <c26e9460-27b6-ed81-2701-e1f3dcbac293-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-01-15 14:44 ` BPJ
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).