Skip to content

Commit

Permalink
feat: add markdown-style conmmand line arg. #68
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 19, 2023
1 parent fff8ba9 commit 33e476b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 16 deletions.
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ inputs:
default: ''
required: false

markdown-style:
description: Markdown wrapper style
default: ''
required: false

outputs:
output:
description: Output static pages to the specified directory
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"prepare": "husky install",
"package": "lerna exec \"ncc build src/action.ts -o dist\" --scope action",
"start": "node packages/cli/lib/cli.js --github-corners-fork --github-corners 'https://jaywcjlove.github.io'",
"watch": "lerna exec \"tsbb watch --disable-babel --no-esm -f src/cli.ts\" --scope markdown-to-html-cli",
"build": "lerna exec \"tsbb build --disable-babel --no-esm -f src/cli.ts\" --scope markdown-to-html-cli && npm run fix",
"watch": "lerna exec \"tsbb watch src/*.ts\" --scope markdown-to-html-cli",
"build": "lerna exec \"tsbb build src/*.ts\" --scope markdown-to-html-cli && npm run fix",
"fix": "lerna exec \"tsc-esm-fix --target='lib' --ext='.js'\" --scope markdown-to-html-cli ",
"test": "tsbb test",
"coverage": "tsbb test --coverage --bail",
Expand Down Expand Up @@ -59,10 +59,10 @@
"ajv": "^8.8.0",
"husky": "^8.0.1",
"jest": "^29.0.0",
"lerna": "^6.0.0",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"tsbb": "^3.7.7",
"tsc-esm-fix": "^2.18.0"
"lerna": "^6.6.2",
"lint-staged": "^13.2.2",
"prettier": "^2.8.8",
"tsbb": "^4.1.5",
"tsc-esm-fix": "^2.20.14"
}
}
13 changes: 8 additions & 5 deletions packages/action/dist/action.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/action/src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RunArgvs, formatConfig, create } from 'markdown-to-html-cli';
const markdown = getInput('markdown');
const corners = getInput('github-corners');
const darkMode = getInput('dark-mode');
const markdownStyle = getInput('markdown-style');
const markdownStyleTheme = getInput('markdown-style-theme');
const options: RunArgvs = {}
info(`source: ${path.resolve(source)}`);
Expand All @@ -25,6 +26,7 @@ import { RunArgvs, formatConfig, create } from 'markdown-to-html-cli';
options.config = config;
options.description = description;
options['github-corners'] = corners;
options['markdown-style'] = markdownStyle;

if (!corners) {
const projectPkg = path.resolve(process.cwd(), config || 'package.json');
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Options:
--markdown Markdown string.
--style Override default styles. css file path or css string.
--markdown-style-theme Setting markdown-style light/dark theme.
--markdown-style Markdown wrapper style
--output, -o Output static pages to the specified directory. Default: "index.html"
--source, -s The path of the target file "README.md". Default: "README.md"
--title The `<title>` tag is required in HTML documents!
Expand Down Expand Up @@ -218,8 +219,14 @@ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
'github-corners'?: string;
/** Github corners style. */
'github-corners-fork'?: boolean;
/** Disable light and dark theme styles button. */
'dark-mode'?: boolean;
/** Setting markdown-style light/dark theme. */
'markdown-style-theme'?: 'dark' | 'light';
/** Markdown string. */
markdown?: string;
/** Markdown wrapper style */
'markdown-style'?: string;
/** The `<title>` tag is required in HTML documents! */
title?: string;
/** Specify the configuration file. Default: `<process.cwd()>/package.json` */
Expand All @@ -232,6 +239,8 @@ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
favicon?: string;
/** Define the author of a page */
author?: string;
/** Override default styles */
style?: string;
}
export interface MDToHTMLOptions extends RunArgvs {
/** [rehype-document](https://github.com/rehypejs/rehype-document#options) options */
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { MDToHTMLOptions } from './index';
export interface CreateOptions extends MDToHTMLOptions { }

export function create(options: MDToHTMLOptions = {}) {
const { markdown: string, document, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true } = options;
const { markdown: string, document, rewrite, reurls = {}, 'markdown-style-theme': markdownStyleTheme, 'dark-mode': darkModeTheme = true, 'markdown-style': wrapperStyle } = options;

const mdOptions: Options = {
hastNode: false,
Expand All @@ -41,7 +41,7 @@ export function create(options: MDToHTMLOptions = {}) {
],
rewrite: (node, index, parent) => {
if ((node.type == 'element' && node.tagName === 'body') || (!document && node.type === 'root')) {
node.children = markdownStyle(node.children as any, markdownStyleTheme);
node.children = markdownStyle(node.children as any, markdownStyleTheme, wrapperStyle);
if (darkModeTheme) {
darkMode().forEach(item => node.children.unshift(item));
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface RunArgvs extends Omit<ParsedArgs, '_'> {
'markdown-style-theme'?: 'dark' | 'light';
/** Markdown string. */
markdown?: string;
/** Markdown wrapper style */
'markdown-style'?: string;
/** The `<title>` tag is required in HTML documents! */
title?: string;
/** Specify the configuration file. Default: `<process.cwd()>/package.json` */
Expand Down Expand Up @@ -62,6 +64,7 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
help: opts.h || opts.help || false,
source: opts.s || opts.source || 'README.md',
markdown: opts.markdown || '',
'markdown-style': 'max-width: 960px;',
description: opts.description || '',
output: opts.o || opts.output || 'index.html',
},
Expand Down Expand Up @@ -114,6 +117,7 @@ export const cliHelp: string = `\n Usage: markdown-to-html [options] [--help|h]
--markdown Markdown string.
--style Override default styles. css file path or css string.
--markdown-style-theme Setting markdown-style light/dark theme.
--markdown-style Markdown wrapper style.
--output, -o Output static pages to the specified directory. Default: "index.html"
--source, -s The path of the target file "README.md". Default: "README.md"
--title The \`<title>\` tag is required in HTML documents!
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/nodes/markdown-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class MarkdownStyle extends HTMLElement {
}
customElements.define('markdown-style', MarkdownStyle);`

export function markdownStyle(child: ElementContent[], markdownStyleTheme?: 'dark' | 'light'): Element[] {
export function markdownStyle(child: ElementContent[], markdownStyleTheme?: 'dark' | 'light', style: string = ''): Element[] {
const properties: Record<string, string> = {
style: 'max-width: 960px; margin: 0 auto 60px auto; padding: 8px',
style: 'max-width: 960px; margin: 0 auto 60px auto; padding: 8px;' + style,
className: 'markdown-style',
}
if (markdownStyleTheme) {
Expand Down

0 comments on commit 33e476b

Please sign in to comment.