diff --git a/README.md b/README.md index 0432241..fbb7bf2 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 2 +Version 1 > [!NOTE] > See `example.mint` for a working usage example. @@ -31,10 +31,6 @@ 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 8b56f71..4dcc88a 100644 --- a/example.mint +++ b/example.mint @@ -3,31 +3,16 @@ /#/ 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 c69e74c..e21ae42 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,invalid-name +# pylint: disable=line-too-long,missing-module-docstring,missing-class-docstring,missing-function-docstring from html import escape from pathlib import Path @@ -53,7 +53,6 @@ class ConverterState: underline = False strike_through = False whitespace_pre = False - alignment = "" # left: < center: | right > justify: = def complete_cycle(self): self.pos += self.pos_offset @@ -83,11 +82,6 @@ class MintToHtmlConverter: - underline /u/ - deleted (strike-through) /d/ - - align to left // - - align justified /=/ - - keep whitespaces /e/ - line breaks /l/ ''' @@ -99,9 +93,8 @@ class MintToHtmlConverter: ): self.escape_html = escape_html self.css = css - self.comment_tag = MintTagToHtml("#", None, "comment") self.tags = [ - self.comment_tag, + MintTagToHtml("#", None, "comment"), MintTagToHtml("p", "p", "paragraph"), MintTagToHtml("q", "blockquote", "blockquote"), MintTagToHtml("h", "h1", "heading"), @@ -113,24 +106,14 @@ 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() @@ -166,7 +149,7 @@ class MintToHtmlConverter: break c1 = text_in[state.pos + 1] if c == TAG_BOUNDARY: - if c1 == TAG_BOUNDARY and not state.comment: + if c1 == TAG_BOUNDARY: # e.g. // -> / state.pos_offset += 1 state.add_output(TAG_BOUNDARY) @@ -175,27 +158,14 @@ class MintToHtmlConverter: if state.pos + 2 < len_text_in: c2 = text_in[state.pos + 2] if c2 == TAG_BOUNDARY: - 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 + # process tags + for t in self.tags: + process_inline_tag(c1, state, t) 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 @@ -205,7 +175,7 @@ if __name__ == "__main__": from argparse import ArgumentParser argp = ArgumentParser() - 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("-i", "--input-file", help="Input file (will read from stdin until eof when omitted)", type=Path, required=False) 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") @@ -221,14 +191,11 @@ if __name__ == "__main__": input_lines = [] for l in stdin: input_lines.append(l) - input_text = "\n".join(input_lines) + input_text = "\n".join(input_lines) # pylint: disable=invalid-name del input_lines else: - 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(f"Reading text from {str(args.input_file)} ...") + input_text = args.input_file.read_text() log("Converting text ...") output_document = MintToHtmlConverter( @@ -239,7 +206,7 @@ if __name__ == "__main__": if args.minify_html: log("Minifying html output ...") import minify_html - output_document = minify_html.minify(output_document) # pylint: disable=no-member + output_document = minify_html.minify(output_document) if args.output_file is None: log("Writing output to stdout ...")