UNPKG

typopo

Version:

Fix frequent microtypography errors in multiple languages. Write neat texts without bothering about typography rules. Typopo works for English, German, Slovak, Czech and Rusyn language.

132 lines (91 loc) 5.26 kB
import { identifyMarkdownCodeTicks, placeMarkdownCodeTicks } from "../../src/utils/markdown.js"; import { describe, it, expect } from "vitest"; let configKeepMarkdownCodeBlocks = { keepMarkdownCodeBlocks: true, }; let configIgnoreMarkdownCodeBlocks = { keepMarkdownCodeBlocks: false, }; describe("Identify markdown code ticks:", () => { let testCase = { "```\ncode\n```": "{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "\t```\ncode\n```": "\t{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "\t\t```\ncode\n```": "\t\t{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}", " ```\ncode\n```": " {{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}", " ```\ncode\n```": " {{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "``code``": "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "``code code``": "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code code{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "``code`` ``code``": "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}} {{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}}", "`code`": "{{typopo__markdown_tick}}code{{typopo__markdown_tick}}", "`code code`": "{{typopo__markdown_tick}}code code{{typopo__markdown_tick}}", "`code` `code`": "{{typopo__markdown_tick}}code{{typopo__markdown_tick}} {{typopo__markdown_tick}}code{{typopo__markdown_tick}}", }; Object.keys(testCase).forEach((key) => { it("unit test", () => { expect(identifyMarkdownCodeTicks(key, configKeepMarkdownCodeBlocks)).toBe(testCase[key]); }); }); }); describe("Place markdown code ticks:", () => { let testCase = { "{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "```\ncode\n```", "\t{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "\t```\ncode\n```", "\t\t{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "\t\t```\ncode\n```", " {{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}": " ```\ncode\n```", " {{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}\ncode\n{{typopo__markdown_tick}}{{typopo__markdown_tick}}{{typopo__markdown_tick}}": " ```\ncode\n```", "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "``code``", "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code code{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "``code code``", "{{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}} {{typopo__markdown_tick}}{{typopo__markdown_tick}}code{{typopo__markdown_tick}}{{typopo__markdown_tick}}": "``code`` ``code``", "{{typopo__markdown_tick}}code{{typopo__markdown_tick}}": "`code`", "{{typopo__markdown_tick}}code code{{typopo__markdown_tick}}": "`code code`", "{{typopo__markdown_tick}}code{{typopo__markdown_tick}} {{typopo__markdown_tick}}code{{typopo__markdown_tick}}": "`code` `code`", }; Object.keys(testCase).forEach((key) => { it("unit test", () => { expect(placeMarkdownCodeTicks(key, configKeepMarkdownCodeBlocks)).toBe(testCase[key]); }); }); }); describe("Ignore markdown code ticks:", () => { let testCase = { "```\ncode\n```": "```\ncode\n```", "\t```\ncode\n```": "\t```\ncode\n```", "\t\t```\ncode\n```": "\t\t```\ncode\n```", " ```\ncode\n```": " ```\ncode\n```", " ```\ncode\n```": " ```\ncode\n```", "``code``": "``code``", "``code code``": "``code code``", "``code`` ``code``": "``code`` ``code``", "`code`": "`code`", "`code code`": "`code code`", "`code` `code`": "`code` `code`", }; Object.keys(testCase).forEach((key) => { it("unit test", () => { expect(identifyMarkdownCodeTicks(key, configIgnoreMarkdownCodeBlocks)).toBe(testCase[key]); }); }); Object.keys(testCase).forEach((key) => { it("unit test", () => { expect(placeMarkdownCodeTicks(key, configIgnoreMarkdownCodeBlocks)).toBe(testCase[key]); }); }); });