ReasonJun

remark / remark-html 본문

Frontend/Library

remark / remark-html

ReasonJun 2023. 6. 17. 18:14
728x90

remark and remark-html are two JavaScript libraries that can be used to process Markdown.

remark is a general-purpose Markdown processor that can be used to do a variety of things, such as:

  • Parsing Markdown into an abstract syntax tree (AST)
  • Transforming the AST into different formats, such as HTML, JSON, or XML
  • Linting Markdown for errors or inconsistencies
  • Adding custom extensions to Markdown

remark-html is a plugin for remark that can be used to transform Markdown into HTML. It provides a number of features, such as:

  • Support for GFM (GitHub Flavored Markdown)
  • Support for custom extensions
  • Configurable output

remark and remark-html are both open source and available on GitHub. They are widely used by developers and are well-supported.

Here is a table that summarizes the key differences between remark and remark-html:

Feature remark remark-html
Purpose General-purpose Markdown processor Markdown to HTML converter
Features Parsing, transforming, linting, extending GFM, custom extensions, configurable output
Use cases A variety of tasks, such as parsing, transforming, linting, and extending Markdown Converting Markdown to HTML
export async function getPostData(id: string) {
  const fullPath = path.join(postsDirectory, `${id}.md`);
  const fileContents = fs.readFileSync(fullPath, 'utf8');

  const matterResult = matter(fileContents);

  const processedContent = await remark()
    .use(remarkHtml)
    .process(matterResult.content);

  const contentHTML = processedContent.toString();

  return {
    id,
    contentHTML,
    ...(matterResult.data as { date: string; title: string }),
  };
}

 

728x90

'Frontend > Library' 카테고리의 다른 글

React Syntax Highlighter Demo (MDX : Markdown for the component era)  (0) 2023.06.20
Date-fns : (a comprehensive set of date and time utilities)  (0) 2023.06.19
fs / path / gray-matter  (0) 2023.06.17
Styled Components  (0) 2023.06.13
Axios  (0) 2023.06.13
Comments