feat(package): modernize package metadata, typings, and test setup for ESM builds
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartmarkdown',
|
||||
version: '3.0.3',
|
||||
description: 'do more with markdown files'
|
||||
version: '3.1.0',
|
||||
description: 'Enhances Markdown file handling with parsing, conversion, and frontmatter support.'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
import * as plugins from './smartmarkdown.plugins.js';
|
||||
|
||||
export type TFrontmatterData = Record<string, unknown>;
|
||||
|
||||
type TYamlNode = plugins.RootContent & {
|
||||
type: 'yaml';
|
||||
value: string;
|
||||
};
|
||||
|
||||
const isYamlNode = (nodeArg: plugins.RootContent): nodeArg is TYamlNode => {
|
||||
return nodeArg.type === 'yaml' && 'value' in nodeArg && typeof nodeArg.value === 'string';
|
||||
};
|
||||
|
||||
export class MdParsedResult {
|
||||
public static async createFromMarkdownString(mdStringArg: string): Promise<MdParsedResult> {
|
||||
const mdParsedResult = new MdParsedResult();
|
||||
@@ -7,24 +18,24 @@ export class MdParsedResult {
|
||||
return mdParsedResult;
|
||||
}
|
||||
|
||||
public originalString: string;
|
||||
public title: string;
|
||||
public html: string;
|
||||
public frontmatterData: {[key: string]: any};
|
||||
public originalString = '';
|
||||
public title = '';
|
||||
public html = '';
|
||||
public frontmatterData: TFrontmatterData = {};
|
||||
|
||||
public async updateFromMarkdownString(mdStringArg: string) {
|
||||
let yamlString: string;
|
||||
public async updateFromMarkdownString(mdStringArg: string): Promise<void> {
|
||||
this.originalString = mdStringArg;
|
||||
let yamlString: string | undefined;
|
||||
const result = await plugins.unified()
|
||||
.use(plugins.remarkParse)
|
||||
.use(plugins.remarkGfm)
|
||||
.use(plugins.remarkFrontmatter, ['yaml', 'toml'])
|
||||
.use(plugins.remarkStringify)
|
||||
.use(plugins.remarkHtml)
|
||||
.use(() => (tree) => {
|
||||
console.dir(tree);
|
||||
const yamlChild = tree.children.find(objectArg => objectArg.type === 'yaml');
|
||||
.use((): plugins.Transformer<plugins.Root> => (tree) => {
|
||||
const yamlChild = tree.children.find(isYamlNode);
|
||||
if (yamlChild) {
|
||||
yamlString = (yamlChild as any).value;
|
||||
yamlString = yamlChild.value;
|
||||
}
|
||||
})
|
||||
.process(mdStringArg);
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
/// <reference path="./smartmarkdown.types.d.ts" />
|
||||
|
||||
// pushrocks scope
|
||||
import * as smartyaml from '@push.rocks/smartyaml';
|
||||
|
||||
export {
|
||||
smartyaml
|
||||
}
|
||||
};
|
||||
|
||||
// third party remark
|
||||
import { unified } from 'unified';
|
||||
import type { Plugin, Transformer } from 'unified';
|
||||
import type { Root, RootContent } from 'mdast';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import remarkParse from 'remark-parse';
|
||||
import remarkFrontmatter from 'remark-frontmatter';
|
||||
@@ -14,10 +18,19 @@ import remarkHtml from 'remark-html';
|
||||
import remarkStringify from 'remark-stringify';
|
||||
|
||||
export { unified, remarkGfm, remarkParse, remarkFrontmatter, remarkHtml, remarkStringify };
|
||||
export type { Plugin, Transformer, Root, RootContent };
|
||||
|
||||
// other third party stuff
|
||||
import turndown from 'turndown';
|
||||
// @ts-ignore
|
||||
import * as turndownPluginGfm from 'turndown-plugin-gfm';
|
||||
import * as rawTurndownPluginGfm from 'turndown-plugin-gfm';
|
||||
|
||||
type TTurndownPlugin = (serviceArg: InstanceType<typeof turndown>) => void;
|
||||
|
||||
const turndownPluginGfm = rawTurndownPluginGfm as {
|
||||
gfm: TTurndownPlugin;
|
||||
strikethrough: TTurndownPlugin;
|
||||
tables: TTurndownPlugin;
|
||||
taskListItems: TTurndownPlugin;
|
||||
};
|
||||
|
||||
export { turndown, turndownPluginGfm };
|
||||
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
declare module 'turndown-plugin-gfm' {
|
||||
export const gfm: unknown;
|
||||
export const strikethrough: unknown;
|
||||
export const tables: unknown;
|
||||
export const taskListItems: unknown;
|
||||
}
|
||||
Reference in New Issue
Block a user