-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Link resolution #458
Merged
Merged
Link resolution #458
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6c7ae12
adding link filtering
mpacer 7c351b8
Include filter link function
mpacer 1216e24
Remove internal mechanism and put in pandocfilters
mpacer a7ca351
Move utility as backup in pandoc utils
mpacer 6326932
Use fallback if you cannot get applyJSONFilters from pandocfilters
mpacer f0b0d3b
Make dependency on new pandocfilters explicit
mpacer 18cbee4
explicit dependency on applyJSONFilters
mpacer 2a45d71
remove commented lines
mpacer 19b9c7f
fix the regex
mpacer dfb6b8f
remove applyJSONFilters
mpacer d07e118
remove wrapped_convert_link
mpacer 178ce3d
change naming scheme for latex link filtering
mpacer e3155e5
remove call to nonexistant wrapped_convert_link
mpacer 6ee0ebb
invoke the superclass appropriately
mpacer fa79c87
Add docstrings, fix comma spacing
mpacer 9f30289
Use python2 compatible syntax
mpacer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
"""A pandoc filter used in converting notebooks to Latex. | ||
Converts links between notebooks to Latex cross-references. | ||
""" | ||
import re | ||
|
||
from pandocfilters import RawInline, applyJSONFilters | ||
|
||
def resolve_references(source): | ||
""" | ||
This applies the resolve_one_reference to the text passed in via the source argument. | ||
|
||
This expects content in the form of a string encoded JSON object as represented | ||
internally in ``pandoc``. | ||
""" | ||
return applyJSONFilters([resolve_one_reference], source) | ||
|
||
def resolve_one_reference(key, val, fmt, meta): | ||
""" | ||
This takes a tuple of arguments that are compatible with ``pandocfilters.walk()`` that | ||
allows identifying hyperlinks in the document and transforms them into valid LaTeX | ||
\\ref{} calls so that linking to headers between cells is possible. | ||
|
||
See the documentation in ``pandocfilters.walk()`` for further information on the meaning | ||
and specification of ``key``, ``val``, ``fmt``, and ``meta``. | ||
""" | ||
|
||
if key == 'Link': | ||
target = val[2][0] | ||
m = re.match(r'#(.+)$', target) | ||
if m: | ||
# pandoc automatically makes labels for headings. | ||
label = m.group(1).lower() | ||
label = re.sub(r'[^\w-]+', '', label) # Strip HTML entities | ||
return RawInline('tex', r'Section \ref{%s}' % label) | ||
|
||
# Other elements will be returned unchanged. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's either put a docstring in or remove the empty docstring (I'm happy for this to have no docstring).