Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Text/Pandoc/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Text/Pandoc/Readers/Docx/Fields.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,6 +58,8 @@ fieldInfo = do
<|>
indexref
<|>
crossref
<|>
addIn
<|>
return UnknownField
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/command/9002.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
<tbody>
</tbody>
</table>
<p>See Table 1 This is my table!</p>
<p>See <a href="#_Ref143272803">Table 1 This is my table!</a></p>
```
Binary file added test/docx/cross_reference.docx
Binary file not shown.
7 changes: 7 additions & 0 deletions test/docx/cross_reference.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ Header 1 ( "title" , [] , [] ) [ Str "TITLE" ]
, Para
[ Str "Cross-reference:"
, Space
, Link ( "" , [] , [] ) [ Str "TITLE" ] ( "#title" , "" )
]
]
40 changes: 35 additions & 5 deletions test/docx/table_captions_with_field.native
Original file line number Diff line number Diff line change
@@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -111,5 +134,12 @@
[ TableBody ( "" , [] , [] ) (RowHeadColumns 0) [] [] ]
(TableFoot ( "" , [] , [] ) [])
, Para
[ Str "See" , Space , Str "Table" , Space , Str "2." ]
]
[ Str "See"
, Space
, Link
( "" , [] , [] )
[ Str "Table" , Space , Str "2" ]
( "#_Ref71265695" , "" )
, Str "."
]
]