Skip to content

Commit

Permalink
fix(cli): Fix markdown style issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 9, 2022
1 parent d3ee5c4 commit 45e8c4c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
32 changes: 19 additions & 13 deletions packages/action/dist/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -98951,6 +98951,8 @@ function copyElement() {





// @ts-ignore


Expand Down Expand Up @@ -98996,24 +98998,36 @@ var getCodeStr = function getCodeStr() {

function lib_create_create() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
// default github css.
var markdown = options.markdown,
_options$document = options.document,
document = _options$document === void 0 ? {} : _options$document,
document = options.document,
_rewrite = options.rewrite,
_options$reurls = options.reurls,
reurls = _options$reurls === void 0 ? {} : _options$reurls,
_options$wrap = options.wrap,
wrap = _options$wrap === void 0 ? {
wrapper: 'div.markdown-body'
} : _options$wrap;
} : _options$wrap; // default github css.

var cssPath = external_path_.resolve(create_dirname, '..', 'github.css');
var cssForkPath = external_path_.resolve(create_dirname, '..', 'github-fork-ribbon.css');
var cssStr = '';

if (external_fs_.existsSync(cssPath)) {
cssStr = external_fs_.readFileSync(cssPath).toString();
}

if (options['github-corners-fork'] && options['github-corners'] && external_fs_.existsSync(cssForkPath)) {
var cssFork = external_fs_.readFileSync(cssForkPath).toString();
cssStr = "".concat(cssStr).concat(cssFork);
}

return unified().use(remark_parse).use(remarkGfm).use(remarkGemoji).use(remark_rehype_lib, {
allowDangerousHtml: true
}).use(rehype_video_lib).use(rehypeRaw).use(document ? rehypeDocument : undefined, _objectSpread2(_objectSpread2({}, document), {}, {
js: [].concat(_toConsumableArray(document && document.js ? Array.isArray(document.js) ? document.js : [document.js] : []), ['https://unpkg.com/@uiw/copy-to-clipboard/dist/copy-to-clipboard.umd.js']),
script: [].concat(_toConsumableArray(document && document.script ? Array.isArray(document.script) ? document.script : [document.script] : []), [script]),
link: document && document.link ? Array.isArray(document.link) ? document.link : [document.link] : [],
style: _toConsumableArray(document ? Array.isArray(document.style) ? document.style : [document.style] : [])
style: [cssStr.toString().replace(/\n/g, '')].concat(_toConsumableArray(document ? Array.isArray(document.style) ? document.style : [document.style] : []))
})).use(rehypeSlug).use(rehypeAutolinkHeadings).use(rehype_wrap, _objectSpread2({}, wrap)).use(rehype_prism, {
ignoreMissing: true
}).use(rehype_attr_lib, {
Expand Down Expand Up @@ -99200,14 +99214,6 @@ function run() {

var options = formatConfig(_objectSpread(_objectSpread({}, opts), argvs));
var output = path.resolve(argvs.output);
var cssStr = fs.readFileSync(path.resolve(_dirname, '..', 'github.css')).toString();

if (options['github-corners-fork'] && options['github-corners']) {
var cssFork = fs.readFileSync(path.resolve(_dirname, '..', 'github-fork-ribbon.css')).toString();
cssStr = "".concat(cssStr).concat(cssFork);
}

options.document.style = cssStr;
var strMarkdown = create(_objectSpread(_objectSpread({}, argvs), options));
fs.writeFileSync(output, strMarkdown);
console.log("\nmarkdown-to-html: \x1B[32;1m".concat(path.relative(process.cwd(), output), "\x1B[0m\n"));
Expand Down
16 changes: 14 additions & 2 deletions packages/cli/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,20 @@ const getCodeStr = (data: ElementContent[] = [], code: string = '') => {
};

export function create(options = {} as MDToHTMLOptions) {
// default github css.
const { markdown, document, rewrite, reurls = {}, wrap = { wrapper: 'div.markdown-body' } } = options;

// default github css.
const cssPath = path.resolve(_dirname, '..', 'github.css');
const cssForkPath = path.resolve(_dirname, '..', 'github-fork-ribbon.css');
let cssStr = '';
if (fs.existsSync(cssPath)) {
cssStr = fs.readFileSync(cssPath).toString();
}
if (options['github-corners-fork'] && options['github-corners'] && fs.existsSync(cssForkPath)) {
let cssFork = fs.readFileSync(cssForkPath).toString();
cssStr = `${cssStr}${cssFork}`;
}

return unified()
.use(remarkParse)
.use(remarkGfm)
Expand All @@ -76,7 +88,7 @@ export function create(options = {} as MDToHTMLOptions) {
script,
],
link: document && document.link ? (Array.isArray(document.link) ? document.link : [document.link]) : [],
style: [...(document ? (Array.isArray(document.style) ? document.style : [document.style]) : []) ],
style: [cssStr.toString().replace(/\n/g, ''), ...(document ? (Array.isArray(document.style) ? document.style : [document.style]) : []) ],
})
.use(rehypeSlug)
.use(rehypeAutolinkHeadings)
Expand Down
8 changes: 0 additions & 8 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ export function run(opts = {} as Omit<RunArgvs, '_'>) {
const options = formatConfig({ ...opts, ...argvs });
const output = path.resolve(argvs.output);

let cssStr = fs.readFileSync(path.resolve(_dirname, '..', 'github.css')).toString();
if (options['github-corners-fork'] && options['github-corners']) {
let cssFork = fs.readFileSync(path.resolve(_dirname, '..', 'github-fork-ribbon.css')).toString();
cssStr = `${cssStr}${cssFork}`;
}

options.document.style = cssStr;

const strMarkdown = create({ ...argvs, ...options });
fs.writeFileSync(output, strMarkdown);
console.log(`\nmarkdown-to-html: \x1b[32;1m${path.relative(process.cwd(), output)}\x1b[0m\n`);
Expand Down

0 comments on commit 45e8c4c

Please sign in to comment.