git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Avoid 0-level headers.
a36a56bJesse Rosenthal
src/Text/Pandoc/Readers/Docx/Parse.hs+5−6
@@ -61,7 +61,7 @@ import Control.Monad.Reader
61import Control.Monad.State.Strict
61import Control.Monad.State.Strict
62import Data.Bits ((.|.))
62import Data.Bits ((.|.))
63import qualified Data.ByteString.Lazy as B
63import qualified Data.ByteString.Lazy as B
64−import Data.Char (chr, isDigit, ord, readLitChar)
64+import Data.Char (chr, ord, readLitChar)
65import Data.List
65import Data.List
66import qualified Data.Map as M
66import qualified Data.Map as M
67import Data.Maybe
67import Data.Maybe
@@ -939,19 +939,18 @@ elemToRunStyle ns element parentStyle
939 }
939 }
940elemToRunStyle _ _ _ = defaultRunStyle
940elemToRunStyle _ _ _ = defaultRunStyle
941
941
942−isNumericNotNull :: String -> Bool
943−isNumericNotNull str = (str /= []) && (all isDigit str)
944−
945getHeaderLevel :: NameSpaces -> Element -> Maybe (String,Int)
942getHeaderLevel :: NameSpaces -> Element -> Maybe (String,Int)
946getHeaderLevel ns element
943getHeaderLevel ns element
947 | Just styleId <- findAttrByName ns "w" "styleId" element
944 | Just styleId <- findAttrByName ns "w" "styleId" element
948 , Just index <- stripPrefix "Heading" styleId
945 , Just index <- stripPrefix "Heading" styleId
949− , isNumericNotNull index = Just (styleId, read index)
946+ , Just n <- stringToInteger index
947+ , n > 0 = Just (styleId, fromInteger n)
950 | Just styleId <- findAttrByName ns "w" "styleId" element
948 | Just styleId <- findAttrByName ns "w" "styleId" element
951 , Just index <- findChildByName ns "w" "name" element >>=
949 , Just index <- findChildByName ns "w" "name" element >>=
952 findAttrByName ns "w" "val" >>=
950 findAttrByName ns "w" "val" >>=
953 stripPrefix "heading "
951 stripPrefix "heading "
954− , isNumericNotNull index = Just (styleId, read index)
952+ , Just n <- stringToInteger index
953+ , n > 0 = Just (styleId, fromInteger n)
955getHeaderLevel _ _ = Nothing
954getHeaderLevel _ _ = Nothing
956
955
957blockQuoteStyleIds :: [String]
956blockQuoteStyleIds :: [String]