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: /#/
+
+/ /l/ Remember to switch back to left-alignment
+
+/l/
+
+Text can also be aligned justified: /=/
+
/p/
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
/p/
+/
+
/s/A Subheading/s/
Mint supports /#/ inline comments and/#/ /b/bold/b/, /i/italic/i/ and /u/underlined/u/ text.
-/#/ put a newline: /#/ /l/
-
You can also /d/strike-through/d/ text to indicate that it has been deleted.
/u//i/Obviously/i/, you can /b/mix/b//u/ styles.
@@ -20,23 +35,32 @@ You can also /d/strike-through/d/ text to indicate that it has been deleted.
/p/
Show off a quote:
+/#/ NOTE: if you want to align a blockquote, put your alignment tag before the /q//#/
+
/q/
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
-/l//l/
-/i/- "de Finibus Bonorum et Malorum", Cicero/i/
+/l/
+/|//i/"de Finibus Bonorum et Malorum", Cicero/i/
/q/
/p/
+/
+
/s/Another Subheading/s/
Enforce a // with "////" to get //u//, //i//, etc.
or an url like https:////example.org
-/e/You can also have sections where whitespaces are kept as-is.
+/e/You can also have "pre-formatted" sections where whitespaces are kept as-is.
... which means you can do stuff like
/u/this/u/.
/e/
+/=/
+
/p/
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
/p/
+
+/>/
+bye :)
diff --git a/mint2html.py b/mint2html.py
index e21ae42..c69e74c 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
@@ -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 to center /|/
+ - align to right />/
+ - 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("/", "/lalgn/")
+ text_in = text_in.replace("/>/", "/ralgn/")
if self.escape_html:
text_in = escape(text_in)
+ text_in = text_in.replace("/lalgn/", "/")
+ text_in = text_in.replace("/ralgn/", "/>/")
# 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
@@ -175,7 +205,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 +221,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 +239,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 ...")