From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Syntax for <mark>?
Date: Fri, 22 Jul 2022 12:17:33 +0200 [thread overview]
Message-ID: <CADAJKhAuoU2Oh_Fp_Wu=8oQ35CcAYsxMSkd_1gpwRNFgnM0KUg@mail.gmail.com> (raw)
In-Reply-To: <CAEe_xxi5QbA__V0JVFptVCpdkgjRr8jhSq0VBfkfPNZKB8Xwag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 2990 bytes --]
I guess you can always use a good old markup injection filter, like the one
attached.
Den tors 21 juli 2022 15:38William Lupton <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org>
skrev:
> OK.
>
> Does that description imply that this only works for HTML output? If so
> then that's different from underline and small caps, which both say:
>
> This will work in all output formats that support XXX.
>
> On Thu, 21 Jul 2022 at 14:13, jmuc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <jmuccigr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> wrote:
>
>>
>> I took a stab at this. PR #8191.
>> On Thursday, 21 July 2022 at 08:58:55 UTC-4 Albert Krewinkel wrote:
>>
>>> William Lupton <wlu...-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> writes:
>>>
>>> > Albert, is .mark documented in the manual? I didn't see it. Presumably
>>> > it could/should have a short section near the existing underline and
>>> > smallcaps sections. Tx, W.
>>>
>>> I believe the only mention is in the changelog of version 2.8:
>>>
>>> > Render a Span with class mark using the <mark> element (Florian
>>> > Beeres, #5797).
>>>
>>> You are probably right about having this documented, although the line
>>> between feature and implementation detail is a bit blurry here. Would
>>> you like to create a PR?
>>>
>>> --
>>> Albert Krewinkel
>>> GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
>>>
>> --
>> 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/860e29b8-0e75-4a89-92c5-205b7b5a48den%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/860e29b8-0e75-4a89-92c5-205b7b5a48den%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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/CAEe_xxi5QbA__V0JVFptVCpdkgjRr8jhSq0VBfkfPNZKB8Xwag%40mail.gmail.com
> <https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxi5QbA__V0JVFptVCpdkgjRr8jhSq0VBfkfPNZKB8Xwag%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
--
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/CADAJKhAuoU2Oh_Fp_Wu%3D8oQ35CcAYsxMSkd_1gpwRNFgnM0KUg%40mail.gmail.com.
[-- Attachment #1.2: Type: text/html, Size: 4745 bytes --]
[-- Attachment #2: mark.lua --]
[-- Type: application/octet-stream, Size: 3884 bytes --]
-- Wrap a Pandoc Span with class `.mark` in highlighting markup
--[===[
## Customization
You can add markup for more output formats to the mark4format table if
and as you need. The top level table keys are Pandoc format names.
The value for each format is a table with up to three fields:
- `pre`: the markup which should go before the Span, e.g `<mark>` in html.
- `post`: the markup which should go after the Span, e.g `</mark>` in html.
- `no_loners`: a boolean indicating whether the filter should leave it to
Pandoc to handle Spans with just a `.mark` class.
This should only be useful for html.
You can leave out those fields which are not needed for a format.
For ease of implementation the filter will insert an empty RawInline
for a missing `pre` or `post`. This shouldn't be a problem.
## Examples
$ cat mark-example.md
[foo]{.mark}
[foo]{.bar .mark}
[foo]{.mark bar=baz}
[foo]{#bar .mark}
[foo]{.bar}
$ pandoc -L mark.lua mark-example.md -w html
<p><mark>foo</mark>
<mark><span class="bar">foo</span></mark>
<mark><span data-bar="baz">foo</span></mark>
<mark><span id="bar">foo</span></mark>
<span class="bar">foo</span></p>
$ pandoc -L mark.lua mark-example.md -w latex
\colorbox[named]{yellow}{foo}
\colorbox[named]{yellow}{{foo}}
\colorbox[named]{yellow}{{foo}}
\colorbox[named]{yellow}{\protect\hypertarget{bar}{}{foo}}
{foo}
## Important note
Pandoc's html writer automatically replaces any `<span>` where the
*first* class is `.mark` with a `<mark>` but it doesn't do so
if `.mark` is a non-first class, so the second span in my example breaks:
$ pandoc mark-example.md -w html
<p><mark>foo</mark>
<span class="bar mark">foo</span>
<mark data-bar="baz">foo</mark>
<mark id="bar">foo</mark>
<span class="bar">foo</span></p>
I consider this a nasty misfeature/bug because the order of classes
should not matter, so this filter works around this by removing any
`.mark` class and preserving any class which has other attributes.
If you think that having to take care that `.mark` is the first class
is a reasonable price to pay comment out the html entry in the
mark4format table or do not use this filter for html output.
## License
This software is Copyright (c) 2022 by Benct Philip Jonsson.
This is free software, licensed under:
The MIT (X11) License
http://www.opensource.org/licenses/mit-license.php
--]===]
local mark4format = {
latex = {
-- Make sure your template loads the xcolor package!
pre = "\\colorbox[named]{yellow}{",
post = '}',
},
html = {
pre = '<mark>',
post = '</mark>',
no_loners = true
},
}
for _,fmt in ipairs{'html5'} do
mark4format[fmt] = mark4format.htmo
end
-- Does a class have a single class as only attribute?
local function has_lone_class (elem)
if not elem.attr then return nil end
if 1 == #elem.classes then
if "" == elem.identifier then
if 0 == #elem.attributes then
return true
end
end
end
return false
end
local function is_not_mark (it) return 'mark' ~= it end
local mark = mark4format[FORMAT]
if mark then
pre = pandoc.RawInline(FORMAT, mark.pre or "")
post = pandoc.RawInline(FORMAT, mark.post or "")
no_loners = mark.no_loners
function Span (span)
if span.classes:includes('mark') then
local rv
-- Optionally disembowel the span
if has_lone_class(span) then
if no_loners then return nil end
rv = span.content
else
-- remove existing .mark class(es)
span.classes = span.classes:filter(is_not_mark)
rv = pandoc.Inlines(span)
end
rv:insert(1, pre) -- prepend markup
rv:insert(post) -- append markup
return rv
end
-- no mark class
return nil
end
else -- a no-op
function Pandoc () return nil end
end
next prev parent reply other threads:[~2022-07-22 10:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 11:26 name name
[not found] ` <282ad19d-eac8-40d0-a741-7f7ae41a7b20n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-07-21 11:29 ` Albert Krewinkel
[not found] ` <87pmhyd7lv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-07-21 11:59 ` William Lupton
[not found] ` <CAEe_xxhSMiL13qZ3Y_xc8uYR-kxQQ-f8V+VzSSpgM1=Zsq74gg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-07-21 12:57 ` Albert Krewinkel
[not found] ` <87h73ad3lk.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-07-21 13:13 ` jmuc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
[not found] ` <860e29b8-0e75-4a89-92c5-205b7b5a48den-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-07-21 13:37 ` William Lupton
[not found] ` <CAEe_xxi5QbA__V0JVFptVCpdkgjRr8jhSq0VBfkfPNZKB8Xwag-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-07-22 10:17 ` BPJ [this message]
[not found] ` <CADAJKhAuoU2Oh_Fp_Wu=8oQ35CcAYsxMSkd_1gpwRNFgnM0KUg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-07-22 11:53 ` William Lupton
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='CADAJKhAuoU2Oh_Fp_Wu=8oQ35CcAYsxMSkd_1gpwRNFgnM0KUg@mail.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).