diff options
| author | John MacFarlane <[email protected]> | 2022-11-19 13:28:10 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-11-19 13:28:10 -0800 |
| commit | 4b4771f062a227153109d0ba2f9d125c82f411a8 (patch) | |
| tree | 4c1b752c619e1951a7d1eff72a2a6bc0c4460b9a | |
| parent | bb0fd13bcba5459e48bafc9be2b2e2d573e22863 (diff) | |
Docx reader: Support parsing of highlighted text.
| -rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 2 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Docx/Parse.hs | 1 | ||||
| -rw-r--r-- | src/Text/Pandoc/Readers/Docx/Parse/Styles.hs | 5 | ||||
| -rw-r--r-- | test/command/7743.md | 56 | ||||
| -rw-r--r-- | test/docx/deep_normalize.native | 2 |
5 files changed, 65 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 4e60f412c..0fe9a3b9f 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -305,6 +305,8 @@ runStyleToTransform rPr' = do emph . go rPr{isItalic = Nothing, isItalicCTL = Nothing} | Just True <- bold rPr = strong . go rPr{isBold = Nothing, isBoldCTL = Nothing} + | Just _ <- rHighlight rPr = + spanWith ("",["mark"],[]) . go rPr{rHighlight = Nothing} | Just True <- isSmallCaps rPr = smallcaps . go rPr{isSmallCaps = Nothing} | Just True <- isStrike rPr = diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs index ad67d6170..c36107da7 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse.hs @@ -313,6 +313,7 @@ leftBiasedMergeRunStyle a b = RunStyle , isStrike = isStrike a <|> isStrike b , isRTL = isRTL a <|> isRTL b , isForceCTL = isForceCTL a <|> isForceCTL b + , rHighlight = rHighlight a <|> rHighlight b , rVertAlign = rVertAlign a <|> rVertAlign b , rUnderline = rUnderline a <|> rUnderline b , rParentStyle = rParentStyle a diff --git a/src/Text/Pandoc/Readers/Docx/Parse/Styles.hs b/src/Text/Pandoc/Readers/Docx/Parse/Styles.hs index df942579a..050bfecbc 100644 --- a/src/Text/Pandoc/Readers/Docx/Parse/Styles.hs +++ b/src/Text/Pandoc/Readers/Docx/Parse/Styles.hs @@ -111,6 +111,7 @@ data RunStyle = RunStyle { isBold :: Maybe Bool , isStrike :: Maybe Bool , isRTL :: Maybe Bool , isForceCTL :: Maybe Bool + , rHighlight :: Maybe Text , rVertAlign :: Maybe VertAlign , rUnderline :: Maybe Text , rParentStyle :: Maybe CharStyle @@ -140,6 +141,7 @@ defaultRunStyle = RunStyle { isBold = Nothing , isStrike = Nothing , isRTL = Nothing , isForceCTL = Nothing + , rHighlight = Nothing , rVertAlign = Nothing , rUnderline = Nothing , rParentStyle = Nothing @@ -275,6 +277,9 @@ elemToRunStyle ns element parentStyle , isStrike = checkOnOff ns rPr (elemName ns "w" "strike") , isRTL = checkOnOff ns rPr (elemName ns "w" "rtl") , isForceCTL = checkOnOff ns rPr (elemName ns "w" "cs") + , rHighlight = + findChildByName ns "w" "highlight" rPr >>= + findAttrByName ns "w" "val" , rVertAlign = findChildByName ns "w" "vertAlign" rPr >>= findAttrByName ns "w" "val" >>= diff --git a/test/command/7743.md b/test/command/7743.md new file mode 100644 index 000000000..6e2e0fbfb --- /dev/null +++ b/test/command/7743.md @@ -0,0 +1,56 @@ +``` +% pandoc -f markdown+mark -t html +==Hi== +^D +<p><mark>Hi</mark></p> +``` + +``` +% pandoc -f markdown+mark -t latex +==Hi== +^D +\hl{Hi} +``` + +``` +% pandoc -f markdown+mark -t rst +==Hi== +^D +:mark:`Hi` +``` + +``` +% pandoc -f html -t markdown+mark +<mark>Hi</mark> +^D +==Hi== +``` + +``` +% pandoc -f html -t markdown +<mark>Hi</mark> +^D +[Hi]{.mark} +``` + +``` +% pandoc -f rst -t markdown+mark +:mark:`Hi` +^D +==Hi== +``` + +``` +% pandoc -f markdown+mark -t docx | pandoc -f docx -t markdown+mark +==Hi== +^D +==Hi== +``` + +``` +% pandoc -f latex -t markdown+mark +\hl{Hi} +^D +==Hi== +``` + diff --git a/test/docx/deep_normalize.native b/test/docx/deep_normalize.native index 9b2089ec8..d3fd06755 100644 --- a/test/docx/deep_normalize.native +++ b/test/docx/deep_normalize.native @@ -3,4 +3,4 @@ ,OrderedList (1,LowerAlpha,DefaultDelim) [[Para [Str "This",Space,Str "is",Space,Str "at",Space,Str "the",Space,Str "second",Space,Str "level"] ,OrderedList (1,LowerRoman,DefaultDelim) - [[Para [Str "This",Space,Str "is",Space,Emph [Str "at",Space,Strong [Str "the",Space,Str "third",Space,Str "level"],Str ",",Space,Str "and",Space,Str "I",Space,Str "want",Space,Str "to"],Space,Str "test",Space,Str "normalization",Space,Str "here."]]]]]]]] + [[Para [Str "This",Space,Str "is",Space,Emph [Str "at",Space,Strong [Str "the",Space,Span ("",["mark"],[]) [Str "th"],Str "i",Span ("",["mark"],[]) [Str "rd"],Space,Str "level"],Str ",",Space,Str "and",Space,Str "I",Space,Str "want",Space,Str "to"],Space,Str "test",Space,Str "normalization",Space,Str "here."]]]]]]]] |
