Add support for mark extension for highlighted text.

+ Extensions: Add `Ext_mark` extension.
  This is not part of the pandoc extensions by default.
+ Markdown reader: parse `==..==` if `mark` extension enabled.
+ Markdown writer: support `mark` extension.
+ Docx writer: render Span with class `mark` as highlighted.
  Currently yellow is hardcoded.
+ LaTeX writer: support highlighted text for Span with class `mark`.
+ RST writer: use special `mark` role for Span with class `mark`.
+ Update MANUAL.txt.

Closes #7743.
This commit is contained in:
John MacFarlane
2022-11-19 10:03:12 -08:00
parent 144bf90ab9
commit 75435381ac
7 changed files with 37 additions and 4 deletions
+9 -2
View File
@@ -140,7 +140,7 @@ When using LaTeX, the following packages need to be available
`--listings` option is used), [`fancyvrb`], [`longtable`],
[`booktabs`], [`graphicx`] (if the document
contains images), [`hyperref`], [`xcolor`],
[`ulem`], [`geometry`] (with the `geometry` variable set),
[`soul`], [`geometry`] (with the `geometry` variable set),
[`setspace`] (with `linestretch`), and
[`babel`] (with `lang`). If `CJKmainfont` is set, [`xeCJK`]
is needed. The use of `xelatex` or `lualatex` as
@@ -191,7 +191,7 @@ footnotes in tables).
[`polyglossia`]: https://ctan.org/pkg/polyglossia
[`prince`]: https://www.princexml.com/
[`setspace`]: https://ctan.org/pkg/setspace
[`ulem`]: https://ctan.org/pkg/ulem
[`soul`]: https://ctan.org/pkg/soul
[`unicode-math`]: https://ctan.org/pkg/unicode-math
[`upquote`]: https://ctan.org/pkg/upquote
[`weasyprint`]: https://weasyprint.org
@@ -5577,6 +5577,13 @@ be rewritten relative to the file containing the link
reference definition, not the file containing the reference link
or image itself, if these differ.
#### Extension: `mark` ####
To highlight out a section of text, begin and end it with
with `==`. Thus, for example,
This ==is deleted text.==
#### Extension: `attributes` ####
Allows attributes to be attached to any inline or block-level
+2
View File
@@ -95,6 +95,7 @@ data Extension =
| Ext_link_attributes -- ^ link and image attributes
| Ext_lists_without_preceding_blankline -- ^ Allow lists without preceding blank
| Ext_literate_haskell -- ^ Enable literate Haskell conventions
| Ext_mark -- ^ Enable ==mark== syntax to highlight text
| Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown iff
-- container has attribute 'markdown'
| Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
@@ -485,6 +486,7 @@ getAllExtensions f = universalExtensions <> getAll f
, Ext_mmd_title_block
, Ext_abbreviations
, Ext_autolink_bare_uris
, Ext_mark
, Ext_mmd_link_attributes
, Ext_mmd_header_identifiers
, Ext_compact_definition_lists
+8
View File
@@ -1509,6 +1509,7 @@ inline = do
'!' -> image
'$' -> math
'~' -> strikeout <|> subscript
'=' -> mark
'<' -> autoLink <|> spanHtml <|> rawHtmlInline <|> ltSign
'\\' -> math <|> escapedNewline <|> escapedChar <|> rawLaTeXInline'
'@' -> cite <|> exampleRef
@@ -1698,6 +1699,13 @@ strikeout = fmap B.strikeout <$>
>> notFollowedBy (char '~')
strikeEnd = try $ string "~~"
mark :: PandocMonad m => MarkdownParser m (F Inlines)
mark = fmap (B.spanWith ("",["mark"],[])) <$>
(guardEnabled Ext_mark >> inlinesBetween markStart markEnd)
where markStart = string "==" >> lookAhead nonspaceChar
>> notFollowedBy (char '=')
markEnd = try $ string "=="
superscript :: PandocMonad m => MarkdownParser m (F Inlines)
superscript = do
fmap B.superscript <$> try (do
+3
View File
@@ -1114,6 +1114,9 @@ inlineToOpenXML' _ (Str str) =
map Elem <$> formattedString str
inlineToOpenXML' opts Space = inlineToOpenXML opts (Str " ")
inlineToOpenXML' opts SoftBreak = inlineToOpenXML opts (Str " ")
inlineToOpenXML' opts (Span ("",["mark"],[]) ils) =
withTextProp (mknode "w:highlight" [("w:val","yellow")] ()) $
inlinesToOpenXML opts ils
inlineToOpenXML' opts (Span ("",["csl-block"],[]) ils) =
inlinesToOpenXML opts ils
inlineToOpenXML' opts (Span ("",["csl-left-margin"],[]) ils) =
+3
View File
@@ -735,6 +735,9 @@ inlineListToLaTeX lst = hcat <$>
inlineToLaTeX :: PandocMonad m
=> Inline -- ^ Inline to convert
-> LW m (Doc Text)
inlineToLaTeX (Span ("",["mark"],[]) lst) = do
modify $ \st -> st{ stStrikeout = True } -- this gives us the soul package
inCmd "hl" <$> inlineListToLaTeX lst
inlineToLaTeX (Span (id',classes,kvs) ils) = do
linkAnchor <- hypertarget False id' empty
lang <- toLang $ lookup "lang" kvs
+9 -2
View File
@@ -85,6 +85,10 @@ escapeText opts = T.pack . go' . T.unpack
| isAlphaNum c = '\\' : go (c:cs)
| otherwise = '\\':'\\': go cs
go ('!':'[':cs) = '\\':'!':'[': go cs
go ('=':'=':cs)
| isEnabled Ext_mark opts = '\\':'=':go ('=':cs)
go ('~':'~':cs)
| isEnabled Ext_strikeout opts = '\\':'~':go ('~':cs)
go (c:cs) =
case c of
'[' -> '\\':c:go cs
@@ -98,8 +102,7 @@ escapeText opts = T.pack . go' . T.unpack
| otherwise -> "&lt;" ++ go cs
'|' | isEnabled Ext_pipe_tables opts -> '\\':'|':go cs
'^' | isEnabled Ext_superscript opts -> '\\':'^':go cs
'~' | isEnabled Ext_subscript opts ||
isEnabled Ext_strikeout opts -> '\\':'~':go cs
'~' | isEnabled Ext_subscript opts -> '\\':'~':go cs
'$' | isEnabled Ext_tex_math_dollars opts -> '\\':'$':go cs
'\'' | isEnabled Ext_smart opts -> '\\':'\'':go cs
'"' | isEnabled Ext_smart opts -> '\\':'"':go cs
@@ -344,6 +347,10 @@ inlineToMarkdown opts (Span ("",["emoji"],kvs) [Str s]) =
Just emojiname | isEnabled Ext_emoji opts ->
return $ ":" <> literal emojiname <> ":"
_ -> inlineToMarkdown opts (Str s)
inlineToMarkdown opts (Span ("",["mark"],[]) ils)
| isEnabled Ext_mark opts
= do contents <- inlineListToMarkdown opts ils
return $ "==" <> contents <> "=="
inlineToMarkdown opts (Span attrs ils) = do
variant <- asks envVariant
contents <- inlineListToMarkdown opts ils
+3
View File
@@ -744,6 +744,9 @@ writeInlines lst =
-- | Convert Pandoc inline element to RST.
inlineToRST :: PandocMonad m => Inline -> RST m (Doc Text)
inlineToRST (Span ("",["mark"],[]) ils) = do
contents <- writeInlines ils
return $ ":mark:`" <> contents <> "`"
inlineToRST (Span (_,_,kvs) ils) = do
contents <- writeInlines ils
return $