summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Docx
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2017-08-06 19:26:50 -0700
committerJesse Rosenthal <jrosenthal@jhu.edu>2017-08-06 19:35:03 -0700
commita36a56b8ac5fea612c1d0614d4e1cb14ffc3a21b (patch)
treed980bf45b6d01f6eb1b7256bb772c2cce6368702 /src/Text/Pandoc/Readers/Docx
parent8164a005c0ac9e36d9d1485fcf38e9073a1bcd68 (diff)
Docx reader: Avoid 0-level headers.
We used to parse paragraphs styled with "HeadingN" as "nth-level header." But if a document has a custom style named "Heading0", this will produce a 0-level header, which shouldn't exist. We only parse this style if N>0. Otherwise we treat it as a normal style name, and follow its dependencies, if any. Closes #3830.
Diffstat (limited to 'src/Text/Pandoc/Readers/Docx')
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 24615ba94..05ce691a6 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -61,7 +61,7 @@ import Control.Monad.Reader
import Control.Monad.State.Strict
import Data.Bits ((.|.))
import qualified Data.ByteString.Lazy as B
-import Data.Char (chr, isDigit, ord, readLitChar)
+import Data.Char (chr, ord, readLitChar)
import Data.List
import qualified Data.Map as M
import Data.Maybe
@@ -939,19 +939,18 @@ elemToRunStyle ns element parentStyle
}
elemToRunStyle _ _ _ = defaultRunStyle
-isNumericNotNull :: String -> Bool
-isNumericNotNull str = (str /= []) && (all isDigit str)
-
getHeaderLevel :: NameSpaces -> Element -> Maybe (String,Int)
getHeaderLevel ns element
| Just styleId <- findAttrByName ns "w" "styleId" element
, Just index <- stripPrefix "Heading" styleId
- , isNumericNotNull index = Just (styleId, read index)
+ , Just n <- stringToInteger index
+ , n > 0 = Just (styleId, fromInteger n)
| Just styleId <- findAttrByName ns "w" "styleId" element
, Just index <- findChildByName ns "w" "name" element >>=
findAttrByName ns "w" "val" >>=
stripPrefix "heading "
- , isNumericNotNull index = Just (styleId, read index)
+ , Just n <- stringToInteger index
+ , n > 0 = Just (styleId, fromInteger n)
getHeaderLevel _ _ = Nothing
blockQuoteStyleIds :: [String]