diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 2852defc7083..8f70fe7a637c 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -482,6 +482,7 @@ parPartToInlines' (Field info children) = ++ [("bold","") | entryBold ie] ++ [("italic","") | entryItalic ie])) mempty PagerefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children + CrossrefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children EndNoteCite t -> do formattedCite <- smushInlines <$> mapM parPartToInlines' children opts <- asks docxOptions diff --git a/src/Text/Pandoc/Readers/Docx/Fields.hs b/src/Text/Pandoc/Readers/Docx/Fields.hs index 8b1837394053..89bba8814553 100644 --- a/src/Text/Pandoc/Readers/Docx/Fields.hs +++ b/src/Text/Pandoc/Readers/Docx/Fields.hs @@ -35,6 +35,7 @@ data IndexEntry = IndexEntry data FieldInfo = HyperlinkField URL -- The boolean indicates whether the field is a hyperlink. | PagerefField Anchor Bool + | CrossrefField Anchor Bool | IndexrefField IndexEntry | CslCitation T.Text | CslBibliography @@ -57,6 +58,8 @@ fieldInfo = do <|> indexref <|> + crossref + <|> addIn <|> return UnknownField @@ -141,6 +144,15 @@ pageref = do let isLink = any ((== 'h') . fst) switches return $ PagerefField farg isLink +crossref :: Parser FieldInfo +crossref = do + string "REF" + spaces + farg <- fieldArgument + switches <- many fieldSwitch + let isLink = any ((== 'h') . fst) switches + return $ CrossrefField farg isLink + -- second element of tuple is optional "see". indexref :: Parser FieldInfo indexref = do diff --git a/test/command/9002.md b/test/command/9002.md index 91f98388163f..bac9d23bcaf1 100644 --- a/test/command/9002.md +++ b/test/command/9002.md @@ -16,5 +16,5 @@ -

See Table 1 This is my table!

+

See Table 1 This is my table!

``` diff --git a/test/docx/cross_reference.docx b/test/docx/cross_reference.docx new file mode 100644 index 000000000000..a0efe8386b8a Binary files /dev/null and b/test/docx/cross_reference.docx differ diff --git a/test/docx/cross_reference.native b/test/docx/cross_reference.native new file mode 100644 index 000000000000..eb58cde2a7d4 --- /dev/null +++ b/test/docx/cross_reference.native @@ -0,0 +1,7 @@ +[ Header 1 ( "title" , [] , [] ) [ Str "TITLE" ] +, Para + [ Str "Cross-reference:" + , Space + , Link ( "" , [] , [] ) [ Str "TITLE" ] ( "#title" , "" ) + ] +] diff --git a/test/docx/table_captions_with_field.native b/test/docx/table_captions_with_field.native index 917e6071e276..5fd802602a71 100644 --- a/test/docx/table_captions_with_field.native +++ b/test/docx/table_captions_with_field.native @@ -1,8 +1,23 @@ [ Para - [ Str "See" , Space , Str "Table" , Space , Str "1." ] + [ Str "See" + , Space + , Link + ( "" , [] , [] ) + [ Str "Table" , Space , Str "1" ] + ( "#_Ref71265628" , "" ) + , Str "." + ] , Table ( "" , [] , [] ) - (Caption Nothing [ Para [ Str "Table" , Space , Str "1" ] ]) + (Caption + Nothing + [ Para + [ Span ( "_Ref71265628" , [ "anchor" ] , [] ) [] + , Str "Table" + , Space + , Str "1" + ] + ]) [ ( AlignDefault , ColWidth 0.7605739372523824 ) , ( AlignDefault , ColWidth 0.11971303137380876 ) , ( AlignDefault , ColWidth 0.11971303137380876 ) @@ -79,7 +94,15 @@ , Header 2 ( "section" , [] , [] ) [] , Table ( "" , [] , [] ) - (Caption Nothing [ Para [ Str "Table" , Space , Str "2" ] ]) + (Caption + Nothing + [ Para + [ Span ( "_Ref71265695" , [ "anchor" ] , [] ) [] + , Str "Table" + , Space + , Str "2" + ] + ]) [ ( AlignDefault , ColWidth 0.33329636202307006 ) , ( AlignDefault , ColWidth 0.33329636202307006 ) , ( AlignDefault , ColWidth 0.33340727595385977 ) @@ -111,5 +134,12 @@ [ TableBody ( "" , [] , [] ) (RowHeadColumns 0) [] [] ] (TableFoot ( "" , [] , [] ) []) , Para - [ Str "See" , Space , Str "Table" , Space , Str "2." ] -] \ No newline at end of file + [ Str "See" + , Space + , Link + ( "" , [] , [] ) + [ Str "Table" , Space , Str "2" ] + ( "#_Ref71265695" , "" ) + , Str "." + ] +]