Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to v0.2.0 #56

Merged
merged 18 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
build: use the default prettier settings
  • Loading branch information
mogeko committed Jun 18, 2024
commit 4e1057e1f88139d0c2e6a2c87745048591675afe
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: 'github-actions'
directory: '/'
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: 'monthly'
interval: "monthly"

# Deprondabot does not support Yarn2 yet.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ on:
pull_request:
branches: [master]
schedule:
- cron: '30 1 28 * *'
- cron: "30 1 28 * *"

jobs:
CodeQL-Build:
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- '*'
- "*"

jobs:
release:
@@ -39,7 +39,7 @@ jobs:
with:
registry-url: https://npm.pkg.github.com
node-version: 16
scope: '@mogeko'
scope: "@mogeko"
- name: Publish release @latest
run: npm publish
env:
18 changes: 9 additions & 9 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
exports.pluginOptionsSchema = ({ Joi }) => {
return Joi.object({
codeBlockLang: Joi.string()
.default('plantuml')
.description('Name of the codeblock languange.'),
.default("plantuml")
.description("Name of the codeblock languange."),
imageType: Joi.string()
.default('svg')
.description('Type of PlantUML image returned from Web Server.'),
.default("svg")
.description("Type of PlantUML image returned from Web Server."),
server: Joi.string()
.default('https://www.plantuml.com/plantuml')
.description('PlantUML server to generate UML diagrams on-the-fly.'),
.default("https://www.plantuml.com/plantuml")
.description("PlantUML server to generate UML diagrams on-the-fly."),
title: Joi.string()
.default(null)
.description(
'Specifies the title property of the generated PlantUML image.'
"Specifies the title property of the generated PlantUML image."
),
alt: Joi.string()
.default('plantuml')
.default("plantuml")
.description(
'Specifies the alt property of the generated PlantUML image.'
"Specifies the alt property of the generated PlantUML image."
),
});
};
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -31,10 +31,6 @@
"test": "jest ./tests",
"cov": "jest --coverage"
},
"prettier": {
"singleQuote": true,
"tabWidth": 2
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
2 changes: 1 addition & 1 deletion src/@types/plantuml-encoder.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module 'plantuml-encoder' {
declare module "plantuml-encoder" {
export = {
encode,
decode,
4 changes: 2 additions & 2 deletions src/@types/unist-util-flatmap.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'unist-util-flatmap' {
import { Content, Parent, Root } from 'mdast';
declare module "unist-util-flatmap" {
import { Content, Parent, Root } from "mdast";
declare namespace flatMap {
type Fn<T extends Content> = (
node: T,
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import nodeOperator, { NodeOpt } from './lib';
import { Root } from 'mdast';
import nodeOperator, { NodeOpt } from "./lib";
import { Root } from "mdast";

type ParsedTypes = {
markdownAST: Root;
};

type OptionTypes = {
imageType?: 'svg' | 'png';
imageType?: "svg" | "png";
server?: string;
codeBlockLang?: string;
} & NodeOpt;
@@ -15,13 +15,13 @@ export default function remarkPlantUML(
{ markdownAST }: ParsedTypes,
pluginOptions?: OptionTypes
): Root {
const imageType = pluginOptions?.imageType ?? 'svg';
const imageType = pluginOptions?.imageType ?? "svg";
const server = pluginOptions?.server
? pluginOptions.server.charAt(pluginOptions.server.length - 1) == '/'
? pluginOptions.server.charAt(pluginOptions.server.length - 1) == "/"
? pluginOptions.server.substr(0, pluginOptions.server.length - 1)
: pluginOptions.server
: 'https://www.plantuml.com/plantuml';
const codeBlockLang = pluginOptions?.codeBlockLang ?? 'plantuml';
: "https://www.plantuml.com/plantuml";
const codeBlockLang = pluginOptions?.codeBlockLang ?? "plantuml";
return nodeOperator(
markdownAST,
(encoded) => {
14 changes: 7 additions & 7 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import plantUMLEncoder = require('plantuml-encoder');
import flatmap = require('unist-util-flatmap');
import { Code, Content, Root } from 'mdast';
import plantUMLEncoder = require("plantuml-encoder");
import flatmap = require("unist-util-flatmap");
import { Code, Content, Root } from "mdast";

export type NodeOpt = {
title?: string | null;
@@ -10,17 +10,17 @@ export type NodeOpt = {
const nodeOperator = (
tree: Root,
fn: (encoded: string) => string,
codeBlockName: string = 'plantuml',
codeBlockName: string = "plantuml",
opt: NodeOpt = { title: null, alt: codeBlockName }
): Root => {
return flatmap<Code>(tree, (node: Code): Content[] => {
return node.type === 'code' && node.lang === codeBlockName
return node.type === "code" && node.lang === codeBlockName
? [
{
type: 'paragraph',
type: "paragraph",
children: [
{
type: 'image',
type: "image",
title: opt.title ?? null,
url: fn(plantUMLEncoder.encode(node.value as string)),
alt: opt.alt ?? codeBlockName,
20 changes: 10 additions & 10 deletions tests/gatsby-node.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { testPluginOptionsSchema } = require('gatsby-plugin-utils');
const { pluginOptionsSchema } = require('../gatsby-node');
const { testPluginOptionsSchema } = require("gatsby-plugin-utils");
const { pluginOptionsSchema } = require("../gatsby-node");

test('基础测试', async () => {
test("基础测试", async () => {
const options = {
imageType: 'svg',
imageType: "svg",
};
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
@@ -13,9 +13,9 @@ test('基础测试', async () => {
expect(errors).toEqual([]);
});

test('设置返回的图片类型为 PNG', async () => {
test("设置返回的图片类型为 PNG", async () => {
const options = {
imageType: 'png',
imageType: "png",
};
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
@@ -25,7 +25,7 @@ test('设置返回的图片类型为 PNG', async () => {
expect(errors).toEqual([]);
});

test('测试默认情况', async () => {
test("测试默认情况", async () => {
const options = {
imageType: undefined,
};
@@ -37,7 +37,7 @@ test('测试默认情况', async () => {
expect(errors).toEqual([]);
});

test('测试类型错误的情况', async () => {
test("测试类型错误的情况", async () => {
const options = {
imageType: true, // must be a string
};
@@ -49,9 +49,9 @@ test('测试类型错误的情况', async () => {
expect(errors).toEqual([`"imageType" must be a string`]);
});

test('测试选项不存在的情况', async () => {
test("测试选项不存在的情况", async () => {
const options = {
err: 'svg', // is not allowed
err: "svg", // is not allowed
};
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
40 changes: 20 additions & 20 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Image, Paragraph, Root } from 'mdast';
import fromMarkdown = require('mdast-util-from-markdown');
import remarkPlantUML from '../src/index';
import { Image, Paragraph, Root } from "mdast";
import fromMarkdown = require("mdast-util-from-markdown");
import remarkPlantUML from "../src/index";

describe('基础测试', () => {
describe("基础测试", () => {
let resAst: Root;
let paragraph: Paragraph;
let image: Image;
@@ -17,23 +17,23 @@ describe('基础测试', () => {
image = paragraph.children[0] as Image;
});

test('测试 Wrap (Paragraph) 的类型', () => {
expect(paragraph.type).toEqual('paragraph');
test("测试 Wrap (Paragraph) 的类型", () => {
expect(paragraph.type).toEqual("paragraph");
});

test('测试 Image 的类型', () => {
expect(image.type).toEqual('image');
test("测试 Image 的类型", () => {
expect(image.type).toEqual("image");
});

test('测试 Image 的 Alt', () => {
expect(image.alt).toEqual('plantuml');
test("测试 Image 的 Alt", () => {
expect(image.alt).toEqual("plantuml");
});

test('测试 Image 的 Title', () => {
test("测试 Image 的 Title", () => {
expect(image.title).toEqual(null);
});

test('测试 Image 的 Url', () => {
test("测试 Image 的 Url", () => {
expect(image.url).toMatch(/https:\/\/www\.plantuml\.com/);
expect(image.url).toMatch(/svg/);
expect(image.url).toMatch(
@@ -42,7 +42,7 @@ describe('基础测试', () => {
});
});

describe('测试配置选项', () => {
describe("测试配置选项", () => {
let mdAst: Root;
let paragraph: Paragraph;
let image: Image;
@@ -54,41 +54,41 @@ describe('测试配置选项', () => {
`\`\`\`plantuml\n@startuml\nA -> B: Hello / 你好'\n@enduml\n\`\`\``
),
},
{ imageType: 'png', server: 'https://example.com' }
{ imageType: "png", server: "https://example.com" }
);
paragraph = mdAst.children[0] as Paragraph;
image = paragraph.children[0] as Image;
});

test('测试选项 imageType', () => {
test("测试选项 imageType", () => {
expect(image.url).toMatch(/png/);
});

test('测试选项 server', () => {
test("测试选项 server", () => {
expect(image.url).toMatch(/https:\/\/example.com/);
});
});

test('测试自动格式化 url', () => {
test("测试自动格式化 url", () => {
const rawAst = fromMarkdown(
`\`\`\`plantuml\n@startuml\nA -> B: Hello / 你好'\n@enduml\n\`\`\``
);
const mdAst = remarkPlantUML(
{ markdownAST: rawAst },
{ server: 'https://example.com/' } // will delete the end '/'
{ server: "https://example.com/" } // will delete the end '/'
);
const paragraph = mdAst.children[0] as Paragraph;
const image = paragraph.children[0] as Image;
expect(image.url).toMatch(/https:\/\/example.com/);
});

test('测试自定义 codeBlockLang', () => {
test("测试自定义 codeBlockLang", () => {
const rawAst = fromMarkdown(
`\`\`\`uml\n@startuml\nA -> B: Hello / 你好'\n@enduml\n\`\`\``
);
const mdAst: Root = remarkPlantUML(
{ markdownAST: rawAst },
{ codeBlockLang: 'uml' }
{ codeBlockLang: "uml" }
);
const paragraph = mdAst.children[0] as Paragraph;
const image = paragraph.children[0] as Image;
Loading