Skip to content

Commit

Permalink
minor: Using shortcuts for increments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaJack committed Feb 29, 2024
1 parent 4af447e commit c3f9f17
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions toc/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, inputFile: str = "", outputFile=None, lineNumbers: bool = Fal
def set_character(self):
# automatically select the comment type from its extension, if not already set
match self.extension:
case "ad" | "adoc" | "asc" | "asciidoc" | "c" | "carbon" | "cc" | "coffee" | "cpp" | "cs" | "css" | "d" | "dart" | "go" | "h" | "hpp" | "htm" | "html" | "hxx" | "java" | "js" | "kt" | "md" | "mdx" | "qmd" | "rmd" | "pas" | "php" | "pp" | "proto" | "qs" | "rs" | "scala" | "sc" | "swift" | "ts" | "typ" | "xml" | "zig":
case "ad" | "adoc" | "asc" | "asciidoc" | "c" | "carbon" | "cc" | "coffee" | "cpp" | "cs" | "css" | "d" | "dart" | "go" | "h" | "hpp" | "htm" | "html" | "hxx" | "java" | "js" | "jsx" | "kt" | "md" | "mdx" | "qmd" | "rmd" | "pas" | "php" | "pp" | "proto" | "qs" | "rs" | "scala" | "sc" | "swift" | "ts" | "typ" | "xml" | "zig":
self.character = "//"
case "ahk" | "asm" | "beancount" | "cl" | "clj" | "cljs" | "cljc" | "edn" | "fasl" | "ini" | "lisp" | "lsp" | "rkt" | "scm" | "ss":
self.character = ";"
Expand All @@ -98,6 +98,8 @@ def set_character(self):
self.character = "C"
case "j":
self.character = "NB."
case "mmd" | "mermaid":
self.character = "%%"
case "ml" | "mli":
self.character = "*"
case "rst":
Expand Down Expand Up @@ -409,7 +411,7 @@ def _process_html(self, data):
# return the character number, not the line number
_untilCurrentMatch = _match.start(0)
# to calculate the line number, let's count the number of "\n" up to the match start, and add 1 to the result
n = n + data.count("\n", _fromLastMatch, _untilCurrentMatch)
n += data.count("\n", _fromLastMatch, _untilCurrentMatch)
_heading_text = _heading_text + " " + str(n)
# update with the position of the current match
_fromLastMatch = _untilCurrentMatch
Expand Down Expand Up @@ -441,7 +443,7 @@ def _process_restructuredtext(self, data):
if self.lineNumbers:
# start counting from _heading_text, not optional overline
_untilCurrentMatch = _match.start(1)
n = n + data.count("\n", _fromLastMatch, _untilCurrentMatch)
n += data.count("\n", _fromLastMatch, _untilCurrentMatch)
_heading_text = _heading_text + " " + str(n)
# update with the position of the current match
_fromLastMatch = _untilCurrentMatch
Expand Down

0 comments on commit c3f9f17

Please sign in to comment.