From 117da118a23ee87b026ea2bbcf44bfea9e855b27 Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Tue, 6 Jan 2026 10:38:57 +0100 Subject: [PATCH 1/2] Allow multiple file inputs for the converter --- mint2html.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mint2html.py b/mint2html.py index e21ae42..0e84f77 100755 --- a/mint2html.py +++ b/mint2html.py @@ -3,7 +3,7 @@ # Copyright (c) 2026, Julian Müller (ChaoticByte) # Licensed under the BSD 3-Clause License -# pylint: disable=line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring +# pylint: disable=line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring,invalid-name from html import escape from pathlib import Path @@ -175,7 +175,7 @@ if __name__ == "__main__": from argparse import ArgumentParser argp = ArgumentParser() - argp.add_argument("-i", "--input-file", help="Input file (will read from stdin until eof when omitted)", type=Path, required=False) + argp.add_argument("-i", "--input-file", help="Input file(s) (will read from stdin until eof when omitted)", type=Path, required=False, nargs="*") argp.add_argument("-o", "--output-file", help="Output file (will print to stdout when omitted)", type=Path, required=False) argp.add_argument("--css", help="Add css to the html output", type=str, default="") argp.add_argument("--no-escape-html", help="Don't escape html in the input", action="store_true") @@ -191,11 +191,14 @@ if __name__ == "__main__": input_lines = [] for l in stdin: input_lines.append(l) - input_text = "\n".join(input_lines) # pylint: disable=invalid-name + input_text = "\n".join(input_lines) del input_lines else: - log(f"Reading text from {str(args.input_file)} ...") - input_text = args.input_file.read_text() + log(f"Reading text from {str([str(f) for f in args.input_file])} ...") + inputs = [] + for f in args.input_file: + inputs.append(f.read_text()) + input_text = "\n".join(inputs) log("Converting text ...") output_document = MintToHtmlConverter( @@ -206,7 +209,7 @@ if __name__ == "__main__": if args.minify_html: log("Minifying html output ...") import minify_html - output_document = minify_html.minify(output_document) + output_document = minify_html.minify(output_document) # pylint: disable=no-member if args.output_file is None: log("Writing output to stdout ...") From 744dff86359e5c4ad873390879ac59eea3a88f71 Mon Sep 17 00:00:00 2001 From: ChaoticByte Date: Tue, 6 Jan 2026 11:42:29 +0100 Subject: [PATCH 2/2] Add support for left, center, right and justified alignment, ignore tags in comments --- README.md | 6 +++++- example.mint | 34 +++++++++++++++++++++++++++++----- mint2html.py | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fbb7bf2..0432241 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ For a syntax- and feature-overview, have a look at [Quick Reference](#quick-refe # Markup -Version 1 +Version 2 > [!NOTE] > See `example.mint` for a working usage example. @@ -31,6 +31,10 @@ Tags toggle a style, so you can start bold text with `/b/` and end it with `/b/` | `/u/.../u/` | `...` | Underlined text | | `/d/.../d/` | `...` | ~~Deleted text~~ | | `/e/.../e/` | `
...
` | Keep whitespaces (spaces, new lines, ...) | +| `/...` | Switch to left text-alignment | +| `/\|/...` | `
...` | Switch to center text-alignment | +| `/>/...` | `
...` | Switch to right text-alignment | +| `/=/...` | `
...` | Switch to justified text-alignment | | `/l/` | `
` | Line-break (new line) | | `//` | `/` | Escape a forward slash | diff --git a/example.mint b/example.mint index 4dcc88a..8b56f71 100644 --- a/example.mint +++ b/example.mint @@ -3,16 +3,31 @@ /#/ Example comment /#/ + +Per default, text is aligned left +/|/ +but you can also center it +/>/ +or align it to the right. + +/#/ put a newline: /#/ + +// +bye :) diff --git a/mint2html.py b/mint2html.py index 0e84f77..c69e74c 100755 --- a/mint2html.py +++ b/mint2html.py @@ -53,6 +53,7 @@ class ConverterState: underline = False strike_through = False whitespace_pre = False + alignment = "" # left: < center: | right > justify: = def complete_cycle(self): self.pos += self.pos_offset @@ -82,6 +83,11 @@ class MintToHtmlConverter: - underline /u/ - deleted (strike-through) /d/ + - align to left // + - align justified /=/ + - keep whitespaces /e/ - line breaks /l/ ''' @@ -93,8 +99,9 @@ class MintToHtmlConverter: ): self.escape_html = escape_html self.css = css + self.comment_tag = MintTagToHtml("#", None, "comment") self.tags = [ - MintTagToHtml("#", None, "comment"), + self.comment_tag, MintTagToHtml("p", "p", "paragraph"), MintTagToHtml("q", "blockquote", "blockquote"), MintTagToHtml("h", "h1", "heading"), @@ -106,14 +113,24 @@ class MintToHtmlConverter: MintTagToHtml("e", "pre", "whitespace_pre"), MintTagToHtml("l", "br", None) ] + self.alignments = { + "<": "left", + "|": "center", + ">": "right", + "=": "justify" + } def __call__(self, text_in: str, ) -> str: '''Convert mint to html''' # replace unwanted characters text_in = text_in.replace("\r", "") # html escape + text_in = text_in.replace("//", "/ralgn/") if self.escape_html: text_in = escape(text_in) + text_in = text_in.replace("/lalgn/", "//") # parsing & conversion state = ConverterState() @@ -149,7 +166,7 @@ class MintToHtmlConverter: break c1 = text_in[state.pos + 1] if c == TAG_BOUNDARY: - if c1 == TAG_BOUNDARY: + if c1 == TAG_BOUNDARY and not state.comment: # e.g. // -> / state.pos_offset += 1 state.add_output(TAG_BOUNDARY) @@ -158,14 +175,27 @@ class MintToHtmlConverter: if state.pos + 2 < len_text_in: c2 = text_in[state.pos + 2] if c2 == TAG_BOUNDARY: - # process tags - for t in self.tags: - process_inline_tag(c1, state, t) + if state.comment: + process_inline_tag(c1, state, self.comment_tag) + else: + for t in self.tags: + process_inline_tag(c1, state, t) + # toggle alignment + if c1 in self.alignments: + state.pos_offset += 2 + if state.alignment == c1: + pass + elif state.alignment != "": + state.add_output("
") + state.add_output(f"
") + state.alignment = c1 if not state.cycle_had_op and not state.comment: state.output += c # complete this cycle's state state.complete_cycle() # cleanup + if state.alignment != "": + state.add_output("
") state.output = state.output.strip() # return result return state.output