public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* There are *four* kinds of emphasis in Markdown! (With a little help from a filter.)
       [not found] ` <CADAJKhAH7R5LhS4o36rYuu3WzMx33dmJCnWLNicHwU2pK8KQkw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-04-07 19:59   ` BPJ
       [not found]     ` <CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: BPJ @ 2022-04-07 19:59 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3328 bytes --]

I just realized that I haven't properly shared a discovery which I made
quite some time ago:


## Fun with nested delimiters

Some time ago I discovered that Pandoc allows you to nest emphasis of the
same
kind inside each other if you use different delimiter characters:

    pandoc -t native
    *_emph-in-emph_* and **__strong-in-strong__**
    ^D
    [ Para
        [ Emph [ Emph [ Str "emph-in-emph" ] ]
        , Space
        , Str "and"
        , Space
        , Strong [ Strong [ Str "strong-in-strong" ] ]
        ]
    ]

## How is this useful?

This can be exploited in a filter, since it is fairly simple to check
if an Emph or Strong element has a single child which is of the same type:

```lua
-- One handler for both types
local handler = function(elem)
  -- If elem has only one child
  if 1 == #elem.content then
    -- and that child is of the same type as elem
    if elem.tag == elem.content[1].tag then
      -- replace the double elem with something
      return do_something_with(elem.tag, elem.content[1].content)
    end
  end
  return nil
end
```

## Putting it to use

This in effect gives us two extra punctuation syntaxes in Markdown.
The most obvious things to use them for is small caps and underlining:

``````lua
-- Dispatch table with the replacement constructors
local other = {
  Emph = pandoc.SmallCaps,
  Strong = pandoc.Underline
}

-- One handler for both types
local handler = function(elem)
  ...
      -- replace the double elem with the other type
      return other[elem.tag](elem.content[1].content)
  ...
end
``````

So now you can do this:

    pandoc -L pandoc-double-emph2scaps-uline.lua -t latex
    *_small caps text_* **__underlined text__**
    ^D
    \textsc{small caps text} \uline{underlined text}

Another use for this trick is for your most used foreign languages:

```lua
-- Dispatch table for my main foreign languages:
other = {
  Emph = function (content)
    return pandoc.Span(content, { lang = 'is' })
  end,
  Strong = function (content)
    return pandoc.Span(content, { lang = 'en' })
  end,
}
```

or for your most frequently used DOCX custom character styles:

```lua
-- Dispatch table for my main custom-styles
other = {
  Emph = function (content)
    return pandoc.Span(content, {[custom-style] = 'MyStyleA'})
  end,
  Strong = function (content)
    return pandoc.Span(content, {[custom-style] = 'MyStyleB'})
  end,
}
```

or you can mix:

```lua
local other = {
  Emph = function (content)
    return pandoc.Span(content, { lang = 'is' })
  end,
  Strong = pandoc.SmallCaps,
}
```

I chose to use the double Emph for SmallCaps and the double Strong for
Underline because in my field small caps are used somewhat frequently and
because I think that the double underscores work as an iconic reminder
that this is underlined text.
If you use underlining more frequently you can easily change the dispatch
table
in the filter code.

-- 
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/CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A%40mail.gmail.com.

[-- Attachment #1.2: Type: text/html, Size: 6387 bytes --]

[-- Attachment #2: pandoc-double-emph2scaps-uline.lua --]
[-- Type: application/octet-stream, Size: 3819 bytes --]

local documentation = [======[# `pandoc-double-emph2scaps-uline.lua`

Pandoc filter which "fakes" punctuation syntax for SmallCaps and Underline
through nested Emph and Strong.

## Fun with nested delimiters

Some time ago I discovered that Pandoc allows you to nest emphasis of the same
kind inside each other if you use different delimiter characters:

    pandoc -t native
    *_emph-in-emph_* and **__strong-in-strong__**
    ^D
    [ Para
        [ Emph [ Emph [ Str "emph-in-emph" ] ]
        , Space
        , Str "and"
        , Space
        , Strong [ Strong [ Str "strong-in-strong" ] ]
        ]
    ]

## How is this useful?
    
This can be exploited in a filter, since it is fairly simple to check
if an Emph or Strong element has a single child which is of the same type:

```lua
-- One handler for both types
local handler = function(elem)
  -- If elem has only one child
  if 1 == #elem.content then
    -- and that child is of the same type as elem
    if elem.tag == elem.content[1].tag then
      -- replace the double elem with something
      return do_something_with(elem.tag, elem.content[1].content)
    end
  end
  return nil
end
```

## Putting it to use

This in effect gives us two extra punctuation syntaxes in Markdown.
The most obvious things to use them for is small caps and underlining:

``````lua
-- Dispatch table with the replacement constructors
local other = {
  Emph = pandoc.SmallCaps,
  Strong = pandoc.Underline
}

-- One handler for both types
local handler = function(elem)
  ...
      -- replace the double elem with the other type
      return other[elem.tag](elem.content[1].content)
  ...
end
``````

So now you can do this:

    pandoc -L pandoc-double-emph2scaps-uline.lua -t latex
    *_small caps text_* **__underlined text__**
    ^D
    \textsc{small caps text} \uline{underlined text}
    
Another use for this trick is for your most used foreign languages:

```lua
-- Dispatch table for my main foreign languages:
other = {
  Emph = function (content)
    return pandoc.Span(content, { lang = 'is' })
  end,
  Strong = function (content)
    return pandoc.Span(content, { lang = 'en' })
  end,
}
```

or for your most frequently used DOCX custom character styles:

```lua
-- Dispatch table for my main custom-styles
other = {
  Emph = function (content)
    return pandoc.Span(content, {[custom-style] = 'MyStyleA'})
  end,
  Strong = function (content)
    return pandoc.Span(content, {[custom-style] = 'MyStyleB'})
  end,
}
```

or you can mix:

```lua
local other = {
  Emph = function (content)
    return pandoc.Span(content, { lang = 'is' })
  end,
  Strong = pandoc.SmallCaps,
}
```

I chose to use the double Emph for SmallCaps and the double Strong for
Underline because in my field small caps are used somewhat frequently and
because I think that the double underscores work as an iconic reminder
that this is underlined text.
If you use underlining more frequently you can easily change the dispatch table
in the filter code.

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
]======]
if '-h' == arg[1] then
  print(documentation)
  os.exit(0)
end

-- Dispatch table with the replacement constructors
local other = {
  Emph = pandoc.SmallCaps,
  Strong = pandoc.Underline
}

-- One handler for both types
local handler = function(elem)
  -- If elem has only one child
  if 1 == #elem.content then
    -- and that child is of the same type as elem
    if elem.tag == elem.content[1].tag then
      -- replace the double elem with the other type
      return other[elem.tag](elem.content[1].content)
    end
  end
  return nil
end

-- Hand the filter to pandoc
return {
  {
    Emph = handler,
    Strong = handler
  }
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: There are *four* kinds of emphasis in Markdown! (With a little help from a filter.)
       [not found]     ` <CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-04-07 23:19       ` John MacFarlane
       [not found]         ` <yh480kv8vk8ot1.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: John MacFarlane @ 2022-04-07 23:19 UTC (permalink / raw)
  To: BPJ, pandoc-discuss


Very inventive. Note that this won't work with commonmark
input, since ****hi**** is strong/strong/hi in commomnmark.

BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I just realized that I haven't properly shared a discovery which I made
> quite some time ago:
>
>
> ## Fun with nested delimiters
>
> Some time ago I discovered that Pandoc allows you to nest emphasis of the
> same
> kind inside each other if you use different delimiter characters:
>
>     pandoc -t native
>     *_emph-in-emph_* and **__strong-in-strong__**
>     ^D
>     [ Para
>         [ Emph [ Emph [ Str "emph-in-emph" ] ]
>         , Space
>         , Str "and"
>         , Space
>         , Strong [ Strong [ Str "strong-in-strong" ] ]
>         ]
>     ]
>
> ## How is this useful?
>
> This can be exploited in a filter, since it is fairly simple to check
> if an Emph or Strong element has a single child which is of the same type:
>
> ```lua
> -- One handler for both types
> local handler = function(elem)
>   -- If elem has only one child
>   if 1 == #elem.content then
>     -- and that child is of the same type as elem
>     if elem.tag == elem.content[1].tag then
>       -- replace the double elem with something
>       return do_something_with(elem.tag, elem.content[1].content)
>     end
>   end
>   return nil
> end
> ```
>
> ## Putting it to use
>
> This in effect gives us two extra punctuation syntaxes in Markdown.
> The most obvious things to use them for is small caps and underlining:
>
> ``````lua
> -- Dispatch table with the replacement constructors
> local other = {
>   Emph = pandoc.SmallCaps,
>   Strong = pandoc.Underline
> }
>
> -- One handler for both types
> local handler = function(elem)
>   ...
>       -- replace the double elem with the other type
>       return other[elem.tag](elem.content[1].content)
>   ...
> end
> ``````
>
> So now you can do this:
>
>     pandoc -L pandoc-double-emph2scaps-uline.lua -t latex
>     *_small caps text_* **__underlined text__**
>     ^D
>     \textsc{small caps text} \uline{underlined text}
>
> Another use for this trick is for your most used foreign languages:
>
> ```lua
> -- Dispatch table for my main foreign languages:
> other = {
>   Emph = function (content)
>     return pandoc.Span(content, { lang = 'is' })
>   end,
>   Strong = function (content)
>     return pandoc.Span(content, { lang = 'en' })
>   end,
> }
> ```
>
> or for your most frequently used DOCX custom character styles:
>
> ```lua
> -- Dispatch table for my main custom-styles
> other = {
>   Emph = function (content)
>     return pandoc.Span(content, {[custom-style] = 'MyStyleA'})
>   end,
>   Strong = function (content)
>     return pandoc.Span(content, {[custom-style] = 'MyStyleB'})
>   end,
> }
> ```
>
> or you can mix:
>
> ```lua
> local other = {
>   Emph = function (content)
>     return pandoc.Span(content, { lang = 'is' })
>   end,
>   Strong = pandoc.SmallCaps,
> }
> ```
>
> I chose to use the double Emph for SmallCaps and the double Strong for
> Underline because in my field small caps are used somewhat frequently and
> because I think that the double underscores work as an iconic reminder
> that this is underlined text.
> If you use underlining more frequently you can easily change the dispatch
> table
> in the filter code.
>
> -- 
> 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/CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A%40mail.gmail.com.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: There are *four* kinds of emphasis in Markdown! (With a little help from a filter.)
       [not found]         ` <yh480kv8vk8ot1.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2022-04-08 11:50           ` Pranesh Prakash
  0 siblings, 0 replies; 3+ messages in thread
From: Pranesh Prakash @ 2022-04-08 11:50 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4368 bytes --]

As the old adage goes: One person's bug is another person's feature. :-)

On Friday, 8 April, 2022 at 4:49:19 am UTC+5:30 John MacFarlane wrote:

>
> Very inventive. Note that this won't work with commonmark
> input, since ****hi**** is strong/strong/hi in commomnmark.
>
> BPJ <mel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I just realized that I haven't properly shared a discovery which I made
> > quite some time ago:
> >
> >
> > ## Fun with nested delimiters
> >
> > Some time ago I discovered that Pandoc allows you to nest emphasis of the
> > same
> > kind inside each other if you use different delimiter characters:
> >
> > pandoc -t native
> > *_emph-in-emph_* and **__strong-in-strong__**
> > ^D
> > [ Para
> > [ Emph [ Emph [ Str "emph-in-emph" ] ]
> > , Space
> > , Str "and"
> > , Space
> > , Strong [ Strong [ Str "strong-in-strong" ] ]
> > ]
> > ]
> >
> > ## How is this useful?
> >
> > This can be exploited in a filter, since it is fairly simple to check
> > if an Emph or Strong element has a single child which is of the same 
> type:
> >
> > ```lua
> > -- One handler for both types
> > local handler = function(elem)
> > -- If elem has only one child
> > if 1 == #elem.content then
> > -- and that child is of the same type as elem
> > if elem.tag == elem.content[1].tag then
> > -- replace the double elem with something
> > return do_something_with(elem.tag, elem.content[1].content)
> > end
> > end
> > return nil
> > end
> > ```
> >
> > ## Putting it to use
> >
> > This in effect gives us two extra punctuation syntaxes in Markdown.
> > The most obvious things to use them for is small caps and underlining:
> >
> > ``````lua
> > -- Dispatch table with the replacement constructors
> > local other = {
> > Emph = pandoc.SmallCaps,
> > Strong = pandoc.Underline
> > }
> >
> > -- One handler for both types
> > local handler = function(elem)
> > ...
> > -- replace the double elem with the other type
> > return other[elem.tag](elem.content[1].content)
> > ...
> > end
> > ``````
> >
> > So now you can do this:
> >
> > pandoc -L pandoc-double-emph2scaps-uline.lua -t latex
> > *_small caps text_* **__underlined text__**
> > ^D
> > \textsc{small caps text} \uline{underlined text}
> >
> > Another use for this trick is for your most used foreign languages:
> >
> > ```lua
> > -- Dispatch table for my main foreign languages:
> > other = {
> > Emph = function (content)
> > return pandoc.Span(content, { lang = 'is' })
> > end,
> > Strong = function (content)
> > return pandoc.Span(content, { lang = 'en' })
> > end,
> > }
> > ```
> >
> > or for your most frequently used DOCX custom character styles:
> >
> > ```lua
> > -- Dispatch table for my main custom-styles
> > other = {
> > Emph = function (content)
> > return pandoc.Span(content, {[custom-style] = 'MyStyleA'})
> > end,
> > Strong = function (content)
> > return pandoc.Span(content, {[custom-style] = 'MyStyleB'})
> > end,
> > }
> > ```
> >
> > or you can mix:
> >
> > ```lua
> > local other = {
> > Emph = function (content)
> > return pandoc.Span(content, { lang = 'is' })
> > end,
> > Strong = pandoc.SmallCaps,
> > }
> > ```
> >
> > I chose to use the double Emph for SmallCaps and the double Strong for
> > Underline because in my field small caps are used somewhat frequently and
> > because I think that the double underscores work as an iconic reminder
> > that this is underlined text.
> > If you use underlining more frequently you can easily change the dispatch
> > table
> > in the filter code.
> >
> > -- 
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A%40mail.gmail.com
> .
>

-- 
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/731b177a-faa1-4b99-bc5f-c154f757b2ccn%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 6358 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-08 11:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CADAJKhAH7R5LhS4o36rYuu3WzMx33dmJCnWLNicHwU2pK8KQkw@mail.gmail.com>
     [not found] ` <CADAJKhAH7R5LhS4o36rYuu3WzMx33dmJCnWLNicHwU2pK8KQkw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-04-07 19:59   ` There are *four* kinds of emphasis in Markdown! (With a little help from a filter.) BPJ
     [not found]     ` <CADAJKhCTQ48TnV0ti3nqhdhTpKUA_vF4cACrDaR5rbRuygkY9A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-04-07 23:19       ` John MacFarlane
     [not found]         ` <yh480kv8vk8ot1.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2022-04-08 11:50           ` Pranesh Prakash

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).