aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-06-12 21:51:09 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-06-12 21:51:09 -0700
commitfa50da30306aafed815a47ae4fc0f2f663bdd54d (patch)
treebd21e01cda34f25e1546b149dcde8d24053a6ae1
parent11bb8627677fb8b49af92d7c55aec07c69f95843 (diff)
downloadpandoc-fa50da30306aafed815a47ae4fc0f2f663bdd54d.tar.gz
OpenDocument writer: Avoid duplicate attributes.
We use the innermost attribute in nested cases. Closes #4634.
-rw-r--r--src/Text/Pandoc/Writers/OpenDocument.hs43
-rw-r--r--test/writer.opendocument2
2 files changed, 24 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs
index f00ae12bf..828aec30f 100644
--- a/src/Text/Pandoc/Writers/OpenDocument.hs
+++ b/src/Text/Pandoc/Writers/OpenDocument.hs
@@ -18,7 +18,7 @@ import Prelude
import Control.Arrow ((***), (>>>))
import Control.Monad.State.Strict hiding (when)
import Data.Char (chr)
-import Data.List (sortBy)
+import Data.List (sortBy, foldl')
import qualified Data.Map as Map
import Data.Maybe (fromMaybe)
import Data.Ord (comparing)
@@ -159,7 +159,8 @@ inTextStyle d = do
[("style:name", styleName)
,("style:family", "text")]
$ selfClosingTag "style:text-properties"
- (concatMap textStyleAttr (Set.toList at)))
+ (sortBy (comparing fst) . Map.toList
+ $ foldl' textStyleAttr mempty (Set.toList at)))
return $ inTags False
"text:span" [("text:style-name",styleName)] d
@@ -692,25 +693,27 @@ data TextStyle = Italic
| Language Lang
deriving ( Eq,Ord )
-textStyleAttr :: TextStyle -> [(String,String)]
-textStyleAttr s
- | Italic <- s = [("fo:font-style" ,"italic" )
- ,("style:font-style-asian" ,"italic" )
- ,("style:font-style-complex" ,"italic" )]
- | Bold <- s = [("fo:font-weight" ,"bold" )
- ,("style:font-weight-asian" ,"bold" )
- ,("style:font-weight-complex" ,"bold" )]
- | Strike <- s = [("style:text-line-through-style", "solid" )]
- | Sub <- s = [("style:text-position" ,"sub 58%" )]
- | Sup <- s = [("style:text-position" ,"super 58%" )]
- | SmallC <- s = [("fo:font-variant" ,"small-caps")]
- | Pre <- s = [("style:font-name" ,"Courier New")
- ,("style:font-name-asian" ,"Courier New")
- ,("style:font-name-complex" ,"Courier New")]
+textStyleAttr :: Map.Map String String
+ -> TextStyle
+ -> Map.Map String String
+textStyleAttr m s
+ | Italic <- s = Map.insert "fo:font-style" "italic" .
+ Map.insert "style:font-style-asian" "italic" .
+ Map.insert "style:font-style-complex" "italic" $ m
+ | Bold <- s = Map.insert "fo:font-weight" "bold" .
+ Map.insert "style:font-weight-asian" "bold" .
+ Map.insert "style:font-weight-complex" "bold" $ m
+ | Strike <- s = Map.insert "style:text-line-through-style" "solid" m
+ | Sub <- s = Map.insert "style:text-position" "sub 58%" m
+ | Sup <- s = Map.insert "style:text-position" "super 58%" m
+ | SmallC <- s = Map.insert "fo:font-variant" "small-caps" m
+ | Pre <- s = Map.insert "style:font-name" "Courier New" .
+ Map.insert "style:font-name-asian" "Courier New" .
+ Map.insert "style:font-name-complex" "Courier New" $ m
| Language lang <- s
- = [("fo:language" ,langLanguage lang)
- ,("fo:country" ,langRegion lang)]
- | otherwise = []
+ = Map.insert "fo:language" (langLanguage lang) .
+ Map.insert "fo:country" (langRegion lang) $ m
+ | otherwise = m
withLangFromAttr :: PandocMonad m => Attr -> OD m a -> OD m a
withLangFromAttr (_,_,kvs) action =
diff --git a/test/writer.opendocument b/test/writer.opendocument
index 95e909029..5cfff6673 100644
--- a/test/writer.opendocument
+++ b/test/writer.opendocument
@@ -1011,7 +1011,7 @@
</text:list-style>
<style:style style:name="T1" style:family="text"><style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" /></style:style>
<style:style style:name="T2" style:family="text"><style:text-properties fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" /></style:style>
- <style:style style:name="T3" style:family="text"><style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" fo:font-weight="bold" style:font-weight-asian="bold" style:font-weight-complex="bold" /></style:style>
+ <style:style style:name="T3" style:family="text"><style:text-properties fo:font-style="italic" fo:font-weight="bold" style:font-style-asian="italic" style:font-style-complex="italic" style:font-weight-asian="bold" style:font-weight-complex="bold" /></style:style>
<style:style style:name="T4" style:family="text"><style:text-properties style:text-line-through-style="solid" /></style:style>
<style:style style:name="T5" style:family="text"><style:text-properties fo:font-style="italic" style:font-style-asian="italic" style:font-style-complex="italic" style:text-line-through-style="solid" /></style:style>
<style:style style:name="T6" style:family="text"><style:text-properties style:text-position="super 58%" /></style:style>