Compare commits

..

No commits in common. "main" and "0.1" have entirely different histories.
main ... 0.1

4 changed files with 105 additions and 182 deletions

28
LICENSE
View file

@ -1,28 +0,0 @@
BSD 3-Clause License
Copyright (c) 2026, Julian Müller (ChaoticByte)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

115
README.md
View file

@ -1,68 +1,97 @@
# MINT - Minimal Text Markup
# mint - Minimal Text Markup
MINT is a minimal text markup language that can be compiled to html.
Mint is a minimal text markup language that can be compiled to html.
For a syntax- and feature-overview, have a look at [Quick Reference](#quick-reference).
As of version 0.1, mint supports
- comments
- headings
- subheadings
- italic text
- bold text
- underline text
- keep whitespaces (html `<pre>`)
- manual line breaks (html `br`)
# Markup
Version 2
# Syntax
> [!NOTE]
> See `example.mint` for a working usage example.
Like HTML, MINT uses tags to style documents.
Like HTML, Mint uses tags to style documents.
A tag consists of a forward slash `/`, one letter (e.g. `b`) and another forward slash.
Tags toggle a style, so you can start bold text with `/b/` and end it with `/b/`.
## Comments
## Quick Reference
```
/#/This is a comment/#/
```
> [!WARNING]
> Comments aren't compiled into html comments, but skipped!
| Markup | HTML | Meaning |
| :---------: | :--------------: | ---------------------- |
| `/#/.../#/` | | Comment (**not compiled into HTML!**) |
| `/p/.../p/` | `<p>...</p>` | Paragraph |
| `/q/.../q/` | `<blockquote>...</blockquote>` | Blockquote |
| `/h/.../h/` | `<h1>...</h1>` | Heading |
| `/s/.../s/` | `<h2>...</h2>` | Subheading |
| `/i/.../i/` | `<i>...</i>` | _Italic text_ |
| `/b/.../b/` | `<b>...</b>` | **Bold text** |
| `/u/.../u/` | `<u>...</u>` | <u>Underlined text</u> |
| `/d/.../d/` | `<s>...</s>` | ~~Deleted text~~ |
| `/e/.../e/` | `<pre>...</pre>` | Keep whitespaces (spaces, new lines, ...) |
| `/</...` | `<section style='text-align: left'>...` | Switch to left text-alignment |
| `/\|/...` | `<section style='text-align: center'>...` | Switch to center text-alignment |
| `/>/...` | `<section style='text-align: right'>...` | Switch to right text-alignment |
| `/=/...` | `<section style='text-align: justify'>...` | Switch to justified text-alignment |
| `/l/` | `<br>` | Line-break (new line) |
| `//` | `/` | Escape a forward slash |
## Headings and Sub-headings
```
/h/Heading/h/
/s/Subheading/s/
```
Headings are compiled into `<h1>`, subheadings into `<h2>`.
## Bold, italic and underlined text
```
Text can be /b/bold/b/, /i/italic/i/ and /u/underlined/u/, or /b//i//u/everything at once/b//i//u/.
```
## Keep whitespaces
Whitespaces (spaces, newlines, etc.) won't get rendered in HTML.
To preserve whitespaces, use
```
/e/
This text
will be indented.
/e/
```
## Newlines
You can insert newlines with
```
/l/
```
> [!NOTE]
> This tag cannot be closed.
## Escape slashes
If you want to write a `/`, use a
```
//
```
# Converter
To convert MINT to HTML, use the `mint2html.py` command-line tool.
To convert mint to html, use `mint2html.py`.
Example:
## Supported platforms
I develop and test on **Linux** with **Python 3.13**, so the code should generally run on Unix-based systems.
There is no code implemented that only works on Unix systems, so it _should_ work on Microslop Windows, although I'm too lazy to test this.
## Example
```bash
```
./mint2html.py -i input_file.mint -o output_file.html
```
You can also omit the input/output files to read from stdin/output to stdout.
Use `mint2html.py --help` to view the full help text.
Tip: If you are in a bash shell, and have pandoc installed, you can pipe the output of mint2html.py directly into pandoc, e.g.:
```bash
./mint2html.py --input-file example.mint --minify | pandoc --from html -o example.epub
```

View file

@ -3,64 +3,34 @@
/#/ 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.
Here you can see /#/ an inline comment and/#/ /b/bold/b/, /i/italic/i/ and /u/underlined/u/ text.
You can also /d/strike-through/d/ text to indicate that it has been deleted.
/#/ put a newline: /#/
/l/
/u//i/Obviously/i/, you can /b/mix/b//u/ styles.
/p/
Show off a quote:
/l//l/
/#/ 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/
/|//i/"de Finibus Bonorum et Malorum", Cicero/i/
/q/
/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?
/s/Another Subheading/s/
Enforce a // with "////" to get //u//, //i//, etc.
or an url like https:////example.org
Enforce a // with "////" to get //u//, //i//, etc..
/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/Can also have blocks where whitespaces are kept as-is.
which means you can do stuff like
/u/this/u/.
/e/
/=/
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.
/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/
/l//l/
/>/
bye :)
https:////example.org

View file

@ -1,9 +1,7 @@
#!/usr/bin/env python3
# Copyright 2026 ChaoticByte (Julian Müller)
# 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
@ -42,18 +40,14 @@ class ConverterState:
# wether this cycle actually converted something:
cycle_had_op = False
# (in)active styles/formats/blocks
# (in)active styles/formats
comment = False
paragraph = False
blockquote = False
heading = False
subheading = False
italic = False
bold = False
underline = False
strike_through = False
whitespace_pre = False
alignment = "" # left: < center: | right > justify: =
def complete_cycle(self):
self.pos += self.pos_offset
@ -70,26 +64,14 @@ class MintToHtmlConverter:
'''A simple converter from Mint to HTML
Currently supports:
- comments /#/
- paragraphs /p/
- block quotes /q/
- headings /h/
- subheadings /s/
- italic /i/
- bold /b/
- underline /u/
- deleted (strike-through) /d/
- align to left /</
- align to center /|/
- align to right />/
- align justified /=/
- keep whitespaces /e/
- line breaks /l/
- comments /#/
- heading /h/
- subheading /s/
- italic /i/
- bold /b/
- underline /u/
- keep whitespaces /e/
- line breaks /l/
'''
def __init__(
@ -99,38 +81,24 @@ class MintToHtmlConverter:
):
self.escape_html = escape_html
self.css = css
self.comment_tag = MintTagToHtml("#", None, "comment")
self.tags = [
self.comment_tag,
MintTagToHtml("p", "p", "paragraph"),
MintTagToHtml("q", "blockquote", "blockquote"),
MintTagToHtml("#", None, "comment"),
MintTagToHtml("h", "h1", "heading"),
MintTagToHtml("s", "h2", "subheading"),
MintTagToHtml("i", "i", "italic"),
MintTagToHtml("b", "b", "bold"),
MintTagToHtml("u", "u", "underline"),
MintTagToHtml("d", "s", "strike_through"),
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()
@ -166,7 +134,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 +143,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("</section>")
state.add_output(f"<section style='text-align: {self.alignments[c1]}'>")
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("</section>")
state.output = state.output.strip()
# return result
return state.output
@ -205,7 +160,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 +176,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 +191,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 ...")