diff options
| author | John MacFarlane <[email protected]> | 2022-11-19 10:03:12 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-11-19 12:30:12 -0800 |
| commit | 75435381acf3a2e6f091de8afa27ba2945ae04cd (patch) | |
| tree | 031df0cb6b56fb84c8f28d01f0677a24ad066543 | |
| parent | 144bf90ab92b517dd721baf80f121f86187ccd61 (diff) | |
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.
| -rw-r--r-- | MANUAL.txt | 11 | ||||
| -rw-r--r-- | src/Text/Pandoc/Extensions.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 8 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown/Inline.hs | 11 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 3 |
7 files changed, 37 insertions, 4 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index eb1a50d72..fed4a61dd 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -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 diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index 1751295ad..efe4ed879 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -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 diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 42df8b985..5efc424ce 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -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 diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index 9abe04b7a..3da9a000f 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -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) = diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index d82838e0d..6a402e1c5 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -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 diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index a956692d7..96f8ab055 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -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 -> "<" ++ 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 diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 6c166f279..2ddf8a3e0 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -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 $ |
