Skip to content

Commit

Permalink
Change to --file-scope behavior.
Browse files Browse the repository at this point in the history
Previously a Div with an identifier derived from the filename
would be added around the contents of each file.  This caused
problems for "chunking" files into chapters, e.g. in EPUB.

We no longer add the surrounding Div. This cooperates better with
chunking. Note, however, that if you have relied on the old
behavior to link to the beginning of the contents of a file using
its filename as identifier, that will no longer work.

Closes #8741.
  • Loading branch information
jgm committed Apr 20, 2024
1 parent a331a1c commit 30442b7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 14 deletions.
4 changes: 0 additions & 4 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,6 @@ header when requesting a document from a URL:
identifier `foo` in `subdir/file1.txt` will have its
identifier changed to `subdir__file1.txt__foo`.

In addition, a Div with an identifier based on the filename
will be added around the file's content, so that internal
links to the filename will point to this Div's identifier.

`-F` *PROGRAM*, `--filter=`*PROGRAM*

: Specify an executable to be used as a filter transforming the
Expand Down
7 changes: 1 addition & 6 deletions src/Text/Pandoc/App/Input.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,13 @@ inputToLazyByteString (_, (bs,_)) = BL.fromStrict bs

adjustLinksAndIds :: Extensions -> Text -> [Text] -> Pandoc -> Pandoc
adjustLinksAndIds exts thisfile allfiles
| length allfiles > 1 = addDiv . walk fixInline . walk fixBlock
| length allfiles > 1 = walk fixInline . walk fixBlock
| otherwise = id
where
toIdent :: Text -> Text
toIdent = textToIdentifier exts . T.intercalate "__" .
T.split (\c -> c == '/' || c == '\\')

addDiv :: Pandoc -> Pandoc
addDiv (Pandoc m bs)
| T.null thisfile = Pandoc m bs
| otherwise = Pandoc m [Div (toIdent thisfile,[],[]) bs]

fixBlock :: Block -> Block
fixBlock (CodeBlock attr t) = CodeBlock (fixAttrs attr) t
fixBlock (Header lev attr ils) = Header lev (fixAttrs attr) ils
Expand Down
4 changes: 0 additions & 4 deletions test/command/6384.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
```
% pandoc --wrap=preserve --file-scope command/file1.txt command/file2.txt
^D
<div id="command__file1.txt">
<h1 id="command__file1.txt__zed">Zed</h1>
<p><a href="bar">foo</a>
and <a href="#command__file1.txt__zed">Zed</a>
and <a href="#command__file2.txt__zed">other Zed</a>
and <a href="#command__file2.txt">other file</a>
and <a href="c.md#zed">foreign Zed</a></p>
</div>
<div id="command__file2.txt">
<h2 id="command__file2.txt__zed">Zed</h2>
<p><a href="baz">foo</a></p>
</div>
```

0 comments on commit 30442b7

Please sign in to comment.