git.iko.soy/typeable/pandoc
on master help sign in
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.

commita36a56b8ac5fea612c1d0614d4e1cb14ffc3a21b authorJesse Rosenthal <jrosenthal@jhu.edu> dateSun 6 Aug 2017, 19:26 (9 years ago) parent8164a00
1 file changed+5−6
src/Text/Pandoc/Readers/Docx/Parse.hs+5−6
src/Text/Pandoc/Readers/Docx/Parse.hs+5−6
@@ -61,7 +61,7 @@ import Control.Monad.Reader
6161import Control.Monad.State.Strict
6262import Data.Bits ((.|.))
6363import qualified Data.ByteString.Lazy as B
64−import Data.Char (chr, isDigit, ord, readLitChar)
64+import Data.Char (chr, ord, readLitChar)
6565import Data.List
6666import qualified Data.Map as M
6767import Data.Maybe
@@ -939,19 +939,18 @@ elemToRunStyle ns element parentStyle
939939 }
940940elemToRunStyle _ _ _ = defaultRunStyle
941941
942−isNumericNotNull :: String -> Bool
943−isNumericNotNull str = (str /= []) && (all isDigit str)
944−
945942getHeaderLevel :: NameSpaces -> Element -> Maybe (String,Int)
946943getHeaderLevel ns element
947944 | Just styleId <- findAttrByName ns "w" "styleId" element
948945 , Just index <- stripPrefix "Heading" styleId
949− , isNumericNotNull index = Just (styleId, read index)
946+ , Just n <- stringToInteger index
947+ , n > 0 = Just (styleId, fromInteger n)
950948 | Just styleId <- findAttrByName ns "w" "styleId" element
951949 , Just index <- findChildByName ns "w" "name" element >>=
952950 findAttrByName ns "w" "val" >>=
953951 stripPrefix "heading "
954− , isNumericNotNull index = Just (styleId, read index)
952+ , Just n <- stringToInteger index
953+ , n > 0 = Just (styleId, fromInteger n)
955954getHeaderLevel _ _ = Nothing
956955
957956blockQuoteStyleIds :: [String]