-
Notifications
You must be signed in to change notification settings - Fork 256
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
Replaced AsciiDoc headings with new style #18
Open
mbrukman
wants to merge
176
commits into
krlawrence:main
Choose a base branch
from
mbrukman:asciidoc-headers-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Fixes krlawrence#17. As described in the Asciidoc best practices document: http://asciidoctor.org/docs/asciidoc-recommended-practices/#section-titles using heading markers using underlines of various characters is not recommended for several reasons: * hard to remember which character means which level header * hard to maintain the correct number of characters (must match heading line) This change takes the same approach as a similar change in JanusGraph: JanusGraph/janusgraph@dc67ce7 with some minor modifications to handle Windows-style EOL `\r\n` in this file, whereas the other change works only with UNIX-style EOL `\n`. What that required was stripping just the Windows-style EOL characters before doing the regex matches: ``` line = line.rstrip('\r\n') ``` Note that using `line = line.rstrip()` doesn't work here, because some lines already end with a whitespace character, which leads to spurious diffs. Then, we manually added them back via: ``` sys.stdout.write('%s\r\n' % ...) ``` Using `print` in this case would give us UNIX-style EOL, causing the entire file to show a diff on every line. Here's the entire file with modifications for this run, which may be useful in the future if/when someone needs to reapply this to an AsciiDoc file formatted with Windows EOL chars: ``` #!/usr/bin/python import re import sys def main(argv): # http://asciidoctor.org/docs/asciidoc-recommended-practices/#section-titles patterns = [ (re.compile('^=+$'), '='), (re.compile('^-+$'), '=='), (re.compile('^~+$'), '==='), (re.compile('^\^+$'), '===='), (re.compile('^\++$'), '====='), ] with open(argv[1], 'r') as input_file: prev_line = None curr_line = None for line in input_file.readlines(): line = line.rstrip('\r\n') prev_line = curr_line curr_line = line if prev_line is None: continue for pattern, heading in patterns: if pattern.match(curr_line) and len(prev_line) == len(curr_line): sys.stdout.write('%s %s\r\n' % (heading, prev_line)) prev_line = None curr_line = None break if prev_line is not None: sys.stdout.write('%s\r\n' % prev_line) # end for if curr_line is not None: sys.stdout.write(curr_line) # end with if __name__ == '__main__': main(sys.argv) ```
krlawrence
force-pushed
the
master
branch
4 times, most recently
from
December 25, 2017 16:59
560aff3
to
f218559
Compare
We just started work on a Second Edition of Practical Gremlin. As part of that we will update the entire tool chain and factor in these types of changes. I'm leaving this PR open as a reminder. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #17.
As described in the Asciidoc best practices document:
http://asciidoctor.org/docs/asciidoc-recommended-practices/#section-titles
using heading markers using underlines of various characters is not recommended
for several reasons:
This change takes the same approach as a similar change in JanusGraph:
JanusGraph/janusgraph@dc67ce7
with some minor modifications to handle Windows-style EOL
\r\n
in this file,whereas the other change works only with UNIX-style EOL
\n
.What that required was stripping just the Windows-style EOL characters before doing
the regex matches:
Note that using
line = line.rstrip()
doesn't work here, because some linesalready end with a whitespace character, which leads to spurious diffs.
Then, we manually added them back via:
Using
print
in this case would give us UNIX-style EOL, causing the entire fileto show a diff on every line.
Here's the entire file with modifications for this run, which may be useful in
the future if/when someone needs to reapply this to an AsciiDoc file formatted
with Windows EOL chars: