Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<p align="left">
<a href="https://www.npmjs.com/package/@simplrjs/markdown">
<img src="https://img.shields.io/npm/v/@simplrjs/markdown.svg?style=flat-square" alt="version" />
</a>
<a href="https://travis-ci.org/SimplrJS/markdown">
<img src="https://img.shields.io/travis/SimplrJS/markdown.svg?style=flat-square" alt="build" />
</a>
<a href="https://david-dm.org/simplrjs/markdown">
<img src="https://img.shields.io/david/SimplrJS/markdown.svg?style=flat-square" alt="dependencies" />
</a>
<a href="https://david-dm.org/simplrjs/markdown?type=dev">
<img src="https://img.shields.io/david/dev/SimplrJS/markdown.svg?style=flat-square" alt="devDependencies" />
</a>
<a href="https://coveralls.io/github/SimplrJS/markdown">
<img src="https://img.shields.io/coveralls/github/simplrjs/markdown.svg?style=flat-square" alt="license" />
</a>
</p>

<h1 align="center">@simplrjs/markdown</h1>

Creating markdown made easily.

## Get started
```sh
$ npm install @simplrjs/markdown --save
```

## Features
* Creating Markdown output

## TODO
* Markdown file parser

## Simple examples

Using `MarkdownBuilder`.

```typescript
import * as fs from "fs-extra";
import { MarkdownBuilder } from "@simplrjs/markdown";

const builder = new MarkdownBuilder()
.UnderlineHeader("Markdown Header", 1)
.EmptyLine()
.Text(md => `Hello ${md.Bold("World")}!`)
.Text("It's so easy to print markdown this way!");

fs.writeFile("./text.md", builder.Build());
```

You can use `MarkdownGenerator` directly.

```typescript
import * as fs from "fs-extra";
import { MarkdownGenerator } from "@simplrjs/markdown";

let output: string[] = [];

output = output.concat(MarkdownGenerator.UnderlineHeader("Markdown Header", 1));
output.push("");
output.push(`Hello ${MarkdownGenerator.Bold("World")}!`);

fs.writeFile("./text.md", output.join("\n"));
```


## API
WIP

## License
Released under the [MIT license](LICENSE).
77 changes: 77 additions & 0 deletions __tests__/__snapshots__/markdown-builder.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions __tests__/markdown-builder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { MarkdownBuilder } from "../src/markdown-builder";

describe("MarkdownBuilder", () => {
it("Simple builder with GetOutput", () => {
const builder = new MarkdownBuilder()
.Header("Builder simple example", 1)
.EmptyLine()
.Text("It's a simple markdown builder example.");

expect(builder.GetOutput()).toMatchSnapshot();
});

it("Simple builder with Build", () => {
const builder = new MarkdownBuilder()
.Header("Builder simple example", 1)
.EmptyLine()
.Text("It's a simple markdown builder example.");

expect(builder.Build()).toMatchSnapshot();
expect(builder.Build("\n")).toMatchSnapshot();
});

it("All used methods", () => {
const builder = new MarkdownBuilder()
.UnderlineHeader("Foo", 1)
.EmptyLine()
.Header("Bar", 2, true)
.Blockquote("blockquote")
.EmptyLine()
.Link("Link Text", "reference-text", true)
.EmptyLine()
.Link("Link Url", "https://domain.domain", "qwd")
.EmptyLine()
.LinkDefinition("reference", "https://domain.domain")
.EmptyLine()
.Image("Alternative text", "https://domain.domain")
.EmptyLine()
.UnorderedList(["One", "Two"])
.EmptyLine()
.OrderedList(["One", "Two"])
.EmptyLine()
.HorizontalRule()
.EmptyLine()
.Italic("Italic")
.EmptyLine()
.Bold("Bold")
.EmptyLine()
.StrikeThrough("Strike Through")
.EmptyLine()
.InlineCode("Inline code")
.EmptyLine()
.Code(`const a = "Hello World!";`, { lang: "typescript" })
.EmptyLine()
.Table(["A", "B"], [["a1", "b1"]])
.EmptyLine()
.Text("Hello World!")
.Text("It's a simple markdown builder example.");

expect(builder.GetOutput()).toMatchSnapshot();
});

it("Append another Builder while constructing a new one", () => {
const oldBuilder = new MarkdownBuilder()
.UnderlineHeader("Hello Header", 1);

const newBuilder = new MarkdownBuilder(oldBuilder)
.EmptyLine()
.Text(md => `Hello ${md.Bold("World")}!`);

expect(newBuilder).toMatchSnapshot();
});
});
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@simplrjs/markdown",
"version": "0.1.0-beta",
"version": "1.0.0",
"description": "Markdown generator",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -14,18 +14,23 @@
"prepublishOnly": "npm run build && rimraf dist/debug.*"
},
"author": "SimplrJS <simplr@quatrodev.com> (https://github.com/simplrjs)",
"repository": {
"type": "git",
"url": "git+https://github.com/SimplrJS/markdown.git"
},
"contributors": [
"Martynas Žilinskas <martynas@quatrodev.com> (https://github.com/MartynasZilinskas)"
],
"dependencies": {
"@types/string": "0.0.29",
"string": "^3.3.3"
},
"devDependencies": {
"@types/jest": "^21.1.8",
"@types/sinon": "^4.0.0",
"coveralls": "^3.0.0",
"jest": "^21.2.1",
"rimraf": "^2.6.2",
"simplr-tslint": "0.0.1",
"sinon": "^4.1.2",
"ts-jest": "^21.2.4",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as Contracts from "./contracts";

export * from "./markdown-generator";
export * from "./markdown-builder";
export {
Contracts
};
Loading