Browse Source

Updated demo file. Added asciinema file. Bug fix.

master 3.1.0
Franco Masotti 3 years ago
parent
commit
aad4ec201e
  1. 27
      asciinema/md_toc_asciinema_3_1_0.json
  2. 6
      asciinema/md_toc_asciinema_3_1_0_demo.sh
  3. 10
      md_toc/api.py

27
asciinema/md_toc_asciinema_3_1_0.json

@ -0,0 +1,27 @@
{"version": 2, "width": 83, "height": 46, "timestamp": 1553863945, "env": {"SHELL": "/bin/bash", "TERM": "rxvt-unicode-256color"}}
[0.009147, "o", "Running a demo to show some of md_toc's capabilities...\r\n\r\n"]
[2.010888, "o", "$ md_toc -h\r\n"]
[2.194677, "o", "usage: md_toc [-h] [-p] [-l] [-i] [-m TOC_MARKER] [-v]\r\n [FILE_NAME [FILE_NAME ...]]\r\n {github,cmark,gitlab,commonmarker,redcarpet} ...\r\n\r\nMarkdown Table Of Contents: Automatically generate a compliant table\r\nof contents for a markdown file to improve document readability.\r\n\r\npositional arguments:\r\n FILE_NAME the I/O file name\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -p, --in-place overwrite the input file\r\n -l, --no-links avoids adding links to the corresponding content\r\n -i, --no-indentation avoids adding indentations to the corresponding\r\n content\r\n -m TOC_MARKER, --toc-marker TOC_MARKER\r\n set the string to be used as the marker for\r\n positioning the table of contents. Defaults to [](TOC)\r\n -v, --version show program's version number and exit\r\n\r\nmarkdown parser:\r\n {github,cmark,gitlab,commonmarker,redcarpet}\r\n\r\nPlease read the docu"]
[2.194781, "o", "mentation to understand how each parser works\r\n\r\nReturn values: 0 ok, 1 error, 2 invalid command\r\n\r\nCopyright (C) 2018-2019 Franco Masotti, frnmst\r\nLicense GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\r\nThis is free software: you are free to change and redistribute it.\r\nThere is NO WARRANTY, to the extent permitted by law.\r\n"]
[2.206379, "o", "\r\n"]
[7.209793, "o", "Inspecting the file...\r\n$ cat foo.md\r\n"]
[7.211251, "o", "# Hi\r\n\r\n[](TOC)\r\n\r\nhey\r\n\r\n## How are you? !!!\r\n\r\n## fine, thanks\r\n\r\n### Bye\r\n\r\n## Bye bye\r\n\r\n```python\r\n# This is a code\r\n# fence with comments that might represent ATX-style headings\r\n# if not properly parsed\r\n```\r\n\r\nbye\r\n\r\n# boo\r\n"]
[7.211669, "o", "\r\n"]
[12.213709, "o", "Run with default options...\r\n$ md_toc foo.md github\r\n"]
[12.398653, "o", "- [Hi](#hi)\r\n - [How are you? !!!](#how-are-you-----------)\r\n - [fine, thanks](#fine-thanks)\r\n - [Bye](#bye)\r\n - [Bye bye](#bye-bye)\r\n- [boo](#boo)\r\n"]
[12.410272, "o", "\r\n"]
[17.411973, "o", "Ordered list...\r\n$ md_toc foo.md gitlab -o\r\n"]
[17.599974, "o", "1. [Hi](#hi)\r\n 1. [How are you? !!!](#how-are-you-----------)\r\n 2. [fine, thanks](#fine-thanks)\r\n 1. [Bye](#bye)\r\n 3. [Bye bye](#bye-bye)\r\n2. [boo](#boo)\r\n"]
[17.611696, "o", "\r\n"]
[22.613308, "o", "No links...\r\n$ md_toc -l foo.md github\r\n"]
[22.796106, "o", "- Hi\r\n - How are you? !!!\r\n - fine, thanks\r\n - Bye\r\n - Bye bye\r\n- boo\r\n"]
[22.808055, "o", "\r\n"]
[27.809539, "o", "No links and no indentation...\r\n$ md_toc -l -i foo.md github\r\n"]
[27.996843, "o", "- Hi\r\n- How are you? !!!\r\n- fine, thanks\r\n- Bye\r\n- Bye bye\r\n- boo\r\n"]
[28.008569, "o", "\r\n"]
[33.011449, "o", "Use stdin and ...\r\n$ cat foo.md | md_toc -l -i cmark -u '*'\r\n"]
[33.1974, "o", "* Hi\r\n* How are you? !!!\r\n* fine, thanks\r\n* Bye\r\n* Bye bye\r\n* boo\r\n"]
[33.209085, "o", "\r\n"]
[38.210776, "o", "Editing the file in-place. As you can see, code fence detection still needs to be implemented for redcarpet..\r\n$ md_toc -p foo.md redcarpet\r\n"]
[38.407375, "o", "$ cat foo.md\r\n"]
[38.408353, "o", "# Hi\r\n\r\n[](TOC)\r\n\r\n- [Hi](#hi)\r\n - [How are you? !!!](#how-are-you)\r\n - [fine, thanks](#fine-thanks)\r\n - [Bye](#bye)\r\n - [Bye bye](#bye-bye)\r\n- [This is a code](#this-is-a-code)\r\n- [fence with comments that might represent ATX-style headings](#fence-with-comments-that-might-represent-atx-style-headings)\r\n- [if not properly parsed](#if-not-properly-parsed)\r\n- [boo](#boo)\r\n\r\n[](TOC)\r\n\r\nhey\r\n\r\n## How are you? !!!\r\n\r\n## fine, thanks\r\n\r\n### Bye\r\n\r\n## Bye bye\r\n\r\n```python\r\n# This is a code\r\n# fence with comments that might represent ATX-style headings\r\n# if not properly parsed\r\n```\r\n\r\nbye\r\n\r\n# boo\r\n"]

6
asciinema/md_toc_asciinema_3_1_0_demo.sh

@ -90,6 +90,12 @@ md_toc -l -i foo.md github
printf "\n"
sleep 5
printf "Use stdin and ...\n"
printf "$ cat foo.md | md_toc -l -i cmark -u '*'\n"
cat foo.md | md_toc -l -i cmark -u '*'
printf "\n"
sleep 5
printf "Editing the file in-place. As you can see, code fence \
detection still needs to be implemented for redcarpet..\n"
printf "$ md_toc -p foo.md redcarpet\n"

10
md_toc/api.py

@ -171,10 +171,12 @@ def build_multiple_tocs(filenames: list,
#
# See the unit tests (examples 95 and 96 of the github parser)
# and the is_closing_code_fence function.
file_pointer_pos = f.tell()
if f.readline() == str():
is_document_end = True
f.seek(file_pointer_pos)
if filenames[file_id] != '-':
# stdin is not seekable.
file_pointer_pos = f.tell()
if f.readline() == str():
is_document_end = True
f.seek(file_pointer_pos)
# Code fence detection.
if is_within_code_fence:

Loading…
Cancel
Save