Skip to content

Conversation

@Volte6
Copy link
Member

@Volte6 Volte6 commented May 16, 2025

Description

This adds a hand-rolled markdown package, and some basic implementation/usage.

Since markdown is so simple, it didn't make sense to add another dependency to a 3rd party library that has esoteric rules to customizing the output. Particularly because there doesn't seem to be a single great option with a lot of adoption and maintenance, and I don't want to get stuck with a 3rd party library that disappears and have to swap it later. I'd vendor it but there are license restrictions.

This also enables us to add custom markdown if we want, although that quickly becomes a runaway train to generating markdown that's useless to other renderers. I've added a single custom markdown.

There is support for formatters which is an interface with a bunch of methods for custom wrapping the text of each markdown tag/type. I've implemented a few as test cases within the package: HTML, ANSITags, and ReMarkdown (Produces a clean new markdown representation after parsing a markdown document)

Changes

  • Added markdown package
  • templates look for a files ending in .md before .template, and if found use that file, after running through markdown parser.
  • Added attack.md in help files as a testcase/example.
  • Added some ansi classes related to markdown rendering as defaults.
    • ~ (sp1) = command

Supported Markdown

Rules

  • Two line breaks starts a new paragraph of text.
  • Single line breaks collapse into a single line, UNLESS the previous line ended with a double space (Not my convention!)
  • Most wrapping markdown can be nested, bold within emphasis inside of a Heading, etc.

Headings

Markdown:

# Heading

Html:

Html tag output: <h1>Heading</h1>

Ansitags:

<ansi fg="md-h1" bg="md-h1-bg"><ansi fg="md-h1-prefix" bg="md-h1-prefix-bg">.:</ansi> This is a <ansi fg="md-bold" bg="md-bold-bg">HEADING</ansi></ansi>

Note: Adding additional #'s will increment the <h#>
Note: Ansitags only add the prefix for h1

Horizontal Lines

Markdown:

---
===
:::

Html:

<hr />

Ansitags:

<ansi fg="md-hr1" bg="md-hr1-bg">--------------------------------------------------------------------------------</ansi>
<ansi fg="md-hr2" bg="md-hr2-bg">================================================================================</ansi>
<ansi fg="md-hr3" bg="md-hr3-bg">::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</ansi>

Lists

Markdown:

- List Item  1
  - List Sub 1
- List Item 2
- List Item 3

Html:

<ul>
  <li>List Item  1
    <ul>
    <li>List Sub 1</li>
    </ul>
  </li>
  <li>List Item 2</li>
  <li>List Item 3</li>
</ul>

Ansitags:

<ansi fg="md-li" bg="md-li-bg">- List Item  1
  <ansi fg="md-li" bg="md-li-bg">- List Sub 1</ansi></ansi>
<ansi fg="md-li" bg="md-li-bg">- List Item 2</ansi>
<ansi fg="md-li" bg="md-li-bg">- List Item 3</ansi>

Emphasis

Markdown:

*Emphasize me*

Html:

<em>Emphasize me</em>

Ansitags:

<ansi fg="md-em" bg="md-em-bg">Emphasize me</ansi>

Bold

Markdown:

**Bold me**

Html:

<strong>Bold me</strong>

Ansitags:

<ansi fg="md-bold" bg="md-bold-bg">Bold me</ansi>

Special

Markdown:

~I'm Special~

Html:

<span data-special="1">I'm Special</span>

Ansitags:

<ansi fg="md-sp1" bg="md-sp1-bg">I'm Special</ansi>

Notes: Additional wrapping ~'s increment the number: ~~I'm Special~~, ~~~I'm Special~~~ and so on.
Notes: ~~ is typically treated as a strikethrough in markdown.

@Jasrags Jasrags requested a review from Copilot May 19, 2025 16:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a custom markdown package to handle lightweight markdown parsing and formatting without relying on third-party dependencies. It updates template processing to support .md templates, adds a comprehensive markdown AST with multiple formatters (HTML, ANSITags, ReMarkdown), and includes tests and documentation for the new functionality.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/templates/templates.go Updated template processing to detect .md files and integrate markdown parsing.
internal/markdown/parser.go Added the markdown parser that parses various markdown elements into an AST.
internal/markdown/formatter*.go and ast*.go Introduced multiple formatters and the AST structure for the markdown package.
internal/markdown/markdown_test.go Added tests for validating markdown output across different formatters.
_datafiles/world/**/templates/help/* and ansi-aliases Added example markdown templates and updated ANSI alias configurations.
Comments suppressed due to low confidence (2)

internal/templates/templates.go:175

  • The comment indicates that all templates should end with '.template' but this line uses a '.md' extension. Please update the comment to reflect the correct file extension to avoid confusion.
path:       util.FilePath(`templates/`, fname+`.md`), // All templates must end with .template

internal/markdown/parser.go:202

  • The comment appears to be a copy-paste error; 'literal dollars' should be changed to 'literal tildes' to accurately describe the fallback behavior for unmatched '~' characters.
// no closing run → literal dollars

@Jasrags Jasrags added documentation Improvements or additions to documentation enhancement New feature or request labels May 19, 2025
@Volte6 Volte6 merged commit 7d5f961 into master May 28, 2025
6 checks passed
@Volte6 Volte6 deleted the markdown branch May 28, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants