mark

repository·master·Indexed 23 days ago

https://github.com/kovetskiy/mark

A tool to sync Markdown files from a Git repository to Atlassian Confluence pages. It automates page creation, attachment uploads, and Markdown-to-HTML translation via the Confluence REST API. It supports YAML front matter and HTML headers for page metadata, GitHub-style alerts, GFM task lists, custom page layouts, and various Confluence and JIRA macros including code block customization, status badges, and content includes.

Tokens
10.3K
Snippets
19
Records
40
Agent score
81%

What's inside mark

  1. Sync Markdown documentation with Atlassian Confluence

    master

    Mark is a tool designed to sync Markdown files from a Git repository to Atlassian Confluence pages. It automates the process of creating pages, uploading attachments, translating Markdown to HTML, and updating Confluence via the REST API. This allows you to manage documentation in Git without manually using the Confluence editor.

    To use extended features like YAML front matter, you must explicitly enable them using the --features flag, as specifying this flag replaces the default feature set.

    mark --features=mermaid --features=mention --features=frontmatter
  2. Convert GitHub Alerts to Confluence Macros

    master

    The GitHub Alerts transformer allows Mark to convert GitHub-style alert syntax into Confluence structured macros. It identifies specific blockquote patterns and transforms them into the appropriate Confluence macro type while preserving all nested Markdown formatting.

    > [!NOTE]
    > This is a note alert with **markdown** formatting.
  3. Key Features and Compatibility

    master

    Features

    • GitHub Compatibility: Full support for GitHub's alert syntax.
    • Markdown Preservation: All markdown formatting within alerts is preserved.
    • Fallback Support: Regular blockquotes without alert syntax (e.g., > text) remain unchanged and are not converted to macros.
    • User-Friendly Labels: Automatically adds readable labels (Note, Tip, Warning, etc.) to the alert content.

    Backward Compatibility

    • Legacy syntax such as info:, tip:, and warning: continues to work.
    • Regular blockquotes remain unchanged.
  4. Use GitHub-style alerts for Confluence info boxes

    master

    Mark automatically converts GitHub-style alert syntax into Confluence macros. For this to work, the BlockQuote must be at the root level of the document (not nested) and the first line must contain the specific pattern.

    GitHub AlertConfluence MacroDescription
    [!TIP]Tip (green checkmark)Helpful suggestions and best practices
    [!NOTE]Info (blue I in circle)General information and notes
    [!IMPORTANT]Info (blue I in circle)Critical information
    [!WARNING]Note (yellow exclamation)Important warnings and cautions
    [!CAUTION]Warning (red exclamation)Dangerous situations requiring immediate attention

    If the conditions are not met, the block defaults to a standard HTML <blockquote> tag.

    > [!NOTE]
    > This creates a blue info box - perfect for helpful information!
    
    > [!TIP]
    > This creates a green tip box - great for best practices and suggestions!
    
    > [!IMPORTANT]
    > This creates a blue info box - ideal for critical information!
    
    > [!WARNING]
    > This creates a yellow warning box - use for important warnings!
    
    > [!CAUTION]
    > This creates a red warning box - perfect for dangerous situations!
  5. Insert Confluence Table of Contents, PageTree, and Children Display

    master

    Mark provides specialized macros to replicate Confluence navigation components.

    Table of Contents (TOC)

    To insert a TOC, use the ac:toc template. You can parameterize it by defining a macro with the same template name.

    <!-- Macro: :toc:
         Template: ac:toc
         Printable: 'false'
         MinLevel: 2 -->
    
    # Title
    
    :toc:

    Note: Parameters like Printable must be enclosed in single quotes (e.g., 'false').

    PageTree

    Use ac:pagetree to insert a tree rooted at the current page (@self).

    <!-- Macro: :pagetree:
         Template: ac:pagetree
         Reverse: 'true'
         ExpandCollapseAll: 'true'
         StartDepth: 2 -->
    
    :pagetree:

    Children Display

    To display a list of child pages, use the ac:children template.

    <!-- Macro: :children:
         Template: ac:children
         Sort: title
         Style: h3
         Excerpt: simple
         First: 10
         Depth: 2 -->
    
    :children:
    <!-- Include: ac:toc -->
  6. Define placeholders in markdown

    master

    You can define placeholders within your markdown using the following syntax. These are useful for marking areas that require specific content or dynamic insertion.

    <!-- ac:placeholder -->
    Placeholder
    <!-- ac:placeholder end -->
  7. Integrate Mark into CI/CD pipelines

    master

    Mark can be integrated into CI/CD systems (like Snake CI, GitHub Actions, or Bitbucket Pipelines) to automatically sync documentation when changes are merged to a main branch.

    When running in CI, it is recommended to use the --ci flag, which prevents the tool from failing if files are not found. You can use environment variables for credentials to keep them secure.

    stages:
      - sync
    
    Sync documentation:
      stage: sync
      only:
        branches:
          - main
      image: kovetskiy/mark
      commands:
        - for file in $(find -type f -name '*.md'); do
            echo "> Sync $file";
            mark -u $MARK_USER -p $MARK_PASS -b $MARK_URL -f $file || exit 1;
            echo;
          done
  8. Convert Task Lists to Confluence

    master

    Mark supports GitHub Flavored Markdown (GFM) task lists. These are automatically converted to Confluence ac:task-list elements.

    Syntax:

    - [x] Finished task
    - [ ] Unfinished task

    Note on Mixed Lists: If a list contains both tasks and regular list items, Mark falls back to a standard HTML list with textual markers (e.g., [x] or [ ]) to ensure the Confluence storage format remains valid.

  9. Render Diagrams (Mermaid, D2, PlantUML)

    master

    Mark can transform code blocks into images for Confluence.

    Mermaid (Built-in)

    Simply use a mermaid code block. Mark renders it as a PNG and attaches it.

    graph TD;
    A-->B;

    D2 (Requires --features="d2")

    X -> Y

    PlantUML (Requires --features="plantuml")

    Note: This requires the 'PlantUML for Confluence Macro' to be installed in your Confluence instance.

    @startuml
    Alice -> Bob: Authentication Request
    @enduml
  10. Use Templates and Macros in Markdown

    master

    Mark allows you to use custom macros and includes to transform Markdown into Confluence-compatible content.

    Includes

    Use <!-- Include: filename.md --> to insert the contents of another file into your current document.

    Example:

    <!-- Include: disclaimer.md -->
    
    This is my article.

    Macros

    Macros allow you to define reusable patterns with parameters. You define a macro using a comment block and then call it in your text.

    Defining a Macro:

    <!-- Macro: :name:pattern: 
         Template: template_id
         Param1: value1
         ... -->

    Example: Status Badges

    <!-- Macro: :done:
         Template: ac:status
         Title: DONE
         Color: Green -->
    
    * :done: Write Article

    Example: Regex-based Macros (e.g., Jira Tickets) You can use regex to capture parts of a string and pass them to a template:

    <!-- Macro: MYJIRA-\d+
         Template: ac:jira:ticket
         Ticket: ${0} -->
    
    See task MYJIRA-123.
    <!-- Include: disclaimer.md -->
    
    This is my article.
  11. Customize page layout using HTML comments

    master

    When the Layout is set to plain, you can define custom page structures using specific HTML comment tags. This allows you to create sections and cells to organize content. Note that mark does not validate the layout structure, so you must ensure the tags are correctly nested and closed.

    Key tags include:

    • <!-- ac:layout --> / <!-- ac:layout end -->: Wraps the entire layout definition.
    • <!-- ac:layout-section type:<type> --> / <!-- ac:layout-section end -->: Defines a section. Supported types include three_with_sidebars and single.
    • <!-- ac:layout-cell --> / <!-- ac:layout-cell end -->: Defines a cell within a section.
    <!-- Layout: plain -->
    <!-- ac:layout -->
    
    <!-- ac:layout-section type:three_with_sidebars -->
    <!-- ac:layout-cell -->
    More Content
    <!-- ac:layout-cell end -->
    <!-- ac:layout-cell -->
    More Content
    <!-- ac:layout-cell end -->
    <!-- ac:layout-cell -->
    Even More Content
    <!-- ac:layout-cell end -->
    <!-- ac:layout-section end -->
    
    <!-- ac:layout-section type:single -->
    <!-- ac:layout-cell -->
    Still More Content
    <!-- ac:layout-cell end -->
    <!-- ac:layout-section end -->
    
    <!-- ac:layout end -->
  12. Install Mark via Homebrew, Go, or Docker

    master

    You can install the mark CLI tool using several methods:

    Homebrew

    brew tap kovetskiy/mark
    brew install mark

    Go Install

    go install github.com/kovetskiy/mark/v16/cmd/mark@latest

    Docker

    Run the tool directly using a Docker container:

    docker run --rm -i kovetskiy/mark:latest mark <params>

    Manual Compilation (via Docker Compose)

    If you are enhancing the tool, you can build and install it using the provided docker-compose setup:

    # Create the binary
    docker-compose run markbuilder
    # "install" the binary
    cp mark /usr/local/bin
    brew tap kovetskiy/mark
    brew install mark