Git Product home page Git Product logo

markdown-it-textual-uml's Introduction

markdown-it-textual-uml

  1. Overview
  2. UML examples
    1. PlantUML
    2. DOT
    3. ditaa
    4. mermaid
  3. Installation
  4. Usage
    1. Additional steps for mermaid
  5. Development
  6. References
  7. License

Overview

npm NPM npm GitHub Super-Linter

[More project metadata badges here. More CI/CD badges here.]

This is a markdown-it markdown parser plugin to create uml diagrams from text, based on plantuml, mermaid, etc.

At this point the following textual uml offerings are supported:

UML Offering Markdown fence identifier
PlantUML plantuml
DOT dot
ditaa ditaa
mermaid mermaid

UML examples

PlantUML

```plantuml
Bob -> Alice : hello
```

DOT

```dot
digraph example1 {
    1 -> 2 -> { 4, 5 };
    1 -> 3 -> { 6, 7 };
}
```

ditaa

```ditaa
+--------+   +-------+    +-------+
|        +---+ ditaa +--> |       |
|  Text  |   +-------+    |diagram|
|Document|   |!magic!|    |       |
|     {d}|   |       |    |       |
+---+----+   +-------+    +-------+
  :                         ^
  |       Lots of work      |
  +-------------------------+
```

mermaid

```mermaid
graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;
```

Installation

node.js, browser:

npm install markdown-it-textual-uml --save

Usage

const md = require('markdown-it')()
           .use(require('markdown-it-textual-uml'));

Or,

import markdownItTextualUml from 'markdown-it-textual-uml'
const md = require('markdown-it')()
           .use(markdownItTextualUml);

Additional steps for mermaid

For mermaid, you have to include the mermaid js file in your application and initialize it after the window has loaded. Just using this plugin is not enough to ensure that the diagram is rendered correctly.

Note: mermaid js has a dependency on the browser window being loaded before it can initialize. Related GitHub issue.

So you should have the following in your html page in order for the mermaid text definitions to be translated into svg.

<script src="mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>

Details here.

When using some sort of framework, be aware that mermaid.initialize would have to be called after the page has loaded. For example, with vue.js or nuxt.js, this could look like:

<script setup>
import mermaid from 'mermaid'
mermaid.initialize({ startOnLoad: false });
await mermaid.run()
}
</script>

Development

It is highly recommended to use VS Code.

I have an open issue to make development, testing and deployments easier but for now following steps have to be followed:

  1. Make changes in this project.
  2. Update version in package.json.
  3. npm run build
  4. npm run pack
  5. In a separate test project that includes this npm package:
    1. Change the entry in its package.json to: "markdown-it-textual-uml": "file:./markdown-it-textual-uml-0.1.3.tgz". Change version (last released version) to version from step 2.
    2. Run npm cache clean --force.
    3. Delete its package-lock.json.
    4. Delete folder for markdown-it-textual-uml from within the node_modules folder.
    5. Run npm install.

Once we have the changes tested out, revert back all changes in the test project.

Now, in this project:

  1. Run npm run publish.
    1. https://simplernerd.com/update-published-npm-package/
  2. Merge develop to main using Github PR.
  3. Create a GitHub release with the semantically versioned tag against main.
  4. Pull repo to local (optional) if you have main branch locally.

References

Here are some alternative npm packages:

License

MIT

markdown-it-textual-uml's People

Contributors

azat-io avatar dependabot[bot] avatar manastalukdar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ma124

markdown-it-textual-uml's Issues

Implement CI-CD

Implement CI-CD pipelines with the following functionality. Consider using GitHub actions.

Committing code

  • Code should be pushed into master only by using PRs. Disable direct push functionality into master.
  • Disable PRs into master lacking reference to any issue.
  • Disable commits and PRs into develop lacking reference to any issue.

Versioning of packages

Versioning of packages published by different branches:

  • master deploys stable production code. latest tag should be used for the corresponding npm package.
  • develop deploys under-development code. next tag should be used for the corresponding npm package.

Builds

Automated builds should be triggered on:

  • Pushing code to develop.
  • Creating new PR into develop.
  • Creating new PR into master.

Deployments

Automated deployments should be triggered on:

  • Successful build triggered by direct push of code into develop.
  • Successful merge of a PR into develop.
  • Successful merge of a PR into master.

Deployment pipeline should:

  1. Tag the branch with the correct semantic version number. Investigate using some open-source automated semver tooling.
  2. Create GitHub release. The Release text can be initially (and automatically) populated by issues (title and link) referenced by the direct push commit or the PR that just got merged in.
  3. Publish package to npm.
    • On develop package should be tagged as next.
    • On master package should be tagged as latest.
    • Question: What about release candidates? rc tags? Which branch does this go from? Typically this goes from an intermediate release branch. How would this tie into the automation?

It is worth considering if steps 1, 2 and 3 above:

  • should be automated by a deployment pipeline, or
  • should be left as manual, or
  • should be automated but manual deployments should also be allowed.

Status badges

CI/CD status badges should be provided in the README.md file for builds and deployments from both develop and master branches.

Add Types

Add types to mitigate: Could not find a declaration file for module.

Importing this package leads to ERR_REQUIRE_ESM error.

Problem Statement

Importing this module in node 13 leads to ERR_REQUIRE_ESM error.

Description

Seems to be related to this:
nodejs/node#29492
'require' is no longer allowed when "type":"module" is set in package.json.

Platform

Node v13.3.0

Expected behavior

No error occurs.

Observed behavior

The following error occurs:

(node:5061) Warning: require() of ES modules is not supported.
require() of ./node_modules/markdown-it-textual-uml/src/plantuml-parser.js from ./node_modules/markdown-it-textual-uml/src/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename plantuml-parser.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from ./node_modules/markdown-it-textual-uml/package.json.
internal/modules/cjs/loader.js:1163
      throw new ERR_REQUIRE_ESM(filename);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ./node_modules/markdown-it-textual-uml/src/plantuml-parser.js
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1163:13)
    at Module.load (internal/modules/cjs/loader.js:983:32)
    at Function.Module._load (internal/modules/cjs/loader.js:891:14)
    at Module.require (internal/modules/cjs/loader.js:1023:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (./markdown-it-textual-uml/src/index.cjs:3:24)
    at Module._compile (internal/modules/cjs/loader.js:1128:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:983:32)
    at Function.Module._load (internal/modules/cjs/loader.js:891:14) {
  code: 'ERR_REQUIRE_ESM'
}

Steps to reproduce behavior

Import the package:

import MarkdownItTextualUml from 'markdown-it-textual-uml';

Run with node.

Other notes

This can be fixed by deleting the line

"type":"module"

from package.json.

Setup Airbrake for your JavaScript application

Step 1: Add the library

npm install @airbrake/browser

Step 2: Configure the library

(You can find your project ID and API key in your project's settings)

import { Notifier } from '@airbrake/browser';

const airbrake = new Notifier({
  projectId: <Your project ID>,
  projectKey: '<Your project API Key>',
  environment: 'production'
});

To test that Airbrake has been installed correctly in your project, open up the JavaScript console in your browser and paste in:

window.onerror("TestError: This is a test", "path/to/file.js", 123);

Visit our official GitHub repo for more info on alternative configurations and advanced options.

Mermaid does not render on page load from SPA route changes

Overview

Mermaid has a direct dependency on window.load event to start rendering. This is triggered when a page initially loads, or when the page is refreshed. In applications based on many javascript frameworks, entering a page using a router usually does not invoke the window.load event. As a result mermaid does not render the text definitions.

A workaround is to initialize mermaid using the (deprecated) mermaid.init() method and point it to a specific container. There are few disadvantages of this approach:

  1. mermaid.init() is deprecated and kept around only for backwards compatibility. Their documentation clearly recommends not to use it.
  2. If the goal is to render all containers in a page decorated with the class name mermaid, this approach does not work. It works only when the page contains a single container where the text definitions needs to be rendered.

There is a related issue in the mermaid repo.

This issue is to explore a solution to this behavior.

Potential Solutions

  1. https://github.com/yuzutech/kroki
  2. https://mermaid.ink

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.