Coder Social home page Coder Social logo

jaywcjlove / parcel-plugin-markdown-string Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 5.0 510 KB

๐Ÿ“ฆ@parcel-bundler plugin for loader markdown string, markdown output HTML.

Home Page: https://jaywcjlove.github.io/parcel-plugin-markdown-string

License: MIT License

JavaScript 32.02% HTML 27.61% TypeScript 40.37%
parcel-bundler parcel-plugin parceljs markdown markdown-to-html

parcel-plugin-markdown-string's Introduction

parcel-transformer-markdown

Buy me a coffee NPM Downloads Build & Deploy parcel-transformer-markdown version parcel-plugin-markdown-string version

Parcel 2 plugin for loader markdown string, markdown output HTML.

โš ๏ธ parcel-plugin-markdown-string => parcel-transformer-markdown

- parcel-plugin-markdown-string 
+ parcel-transformer-markdown

Example usage

Install the plugin

npm install parcel-transformer-markdown --save-dev

.parcelrc

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.md": [ "parcel-transformer-markdown" ]
  }
}

index.html:

<!DOCTYPE html>
<div id="root"></div>
<script type="module" src="index.js"></script>

Output HTML string

Import your markdown files! Output HTML string.

import HTMLStr from './Markdown.md';

console.log(HTMLStr) // => Output HTML string.
document.body.innerHTML = HTMLStr;

Output Markdown string

// .markedrc
{
  "marked": false
}
import str from './Markdown.md';

console.log(str) // => Output Markdown string.
document.body.innerHTML = str;

Configuration

Marked can be configured using a .markedrc, .markedrc.js, or marked.config.js file. See the Marked API Reference for details on the available options.

Note: .markedrc.js and marked.config.js are supported for JavaScript-based configuration, but should be avoided when possible because they reduce the effectiveness of Parcel's caching. Use a JSON based configuration format (e.g. .markedrc) instead.

There is a marked configuration that converts markdown to HTML. Otherwise just read the markdown string.

{
  "marked": {
    "breaks": true,
    "pedantic": false,
    "gfm": true,
    "tables": true,
    "sanitize": false,
    "smartLists": true,
    "smartypants": false,
    "xhtml": false
  }
}

Contributors

As always, thanks to our amazing contributors!

Made with github-action-contributors.

License

MIT ยฉ Kenny Wong

parcel-plugin-markdown-string's People

Contributors

epimodev avatar jaywcjlove avatar mkg20001 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

parcel-plugin-markdown-string's Issues

following README for getting HTML string didn't work for me

I only got markdown when I was trying to get HTML. By putting console.log statements in the code, I noticed that the default config had:

{ marked: undefined, html: undefined }

I ended up just doing an asset transformation, which is what originally looking for. Would be nice if how to do that were more clearly explained in the README. Here's the example I came up with that seems to work for me:
https://github.com/ultrasaurus/hello-parcel-markdown/tree/simple-asset-transform

basically, just needed to add .markedrc with

{
    "marked": true,
    "html": true
}

then `yarn parcel src/index.md`


Doesn't work with node on Windows because of process.env.PWD

The plugin breaks on parsing Markdown files on Windows machine with the following error (full paths omitted):

ร—  ...\src\...\page.md: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.parse (path.js:910:5)
    at Resolver.findPackage (...\node_modules\parcel-plugin-markdown-string\node_modules\parcel-bundler\src\Resolver.js:419:21)
    at MarkdownAsset.parse (...\node_modules\parcel-plugin-markdown-string\MarkdownAsset.js:10:37)
    at MarkdownAsset.parseIfNeeded (...\node_modules\parcel-plugin-markdown-string\node_modules\parcel-bundler\src\Asset.js:63:29)

The problem is env.PWD - apparently, it's always undefined on non-*NIX systems; process.cwd() can be used instead.

I was able to fix the issue by using patch-package with the following change in MarkdownAsset.js:

class MarkdownAsset extends Asset {
     this.type = 'js';
   }
   async parse(markdownString) {
-    const pkg = await this.resolver.findPackage(this.options.env.PWD);
+    const pkg = await this.resolver.findPackage(process.cwd());
     if (pkg && pkg.marked) {
       this.code = marked(markdownString, pkg.marked);
     } else {

Might as well submit a pull request with this fix, if you want :)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Other Branches

These updates are pending. To force PRs open, click the checkbox below.

  • chore(deps): update actions/checkout action to v4
  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update peaceiris/actions-gh-pages action to v4

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • peaceiris/actions-gh-pages v3
  • ncipollo/release-action v1
npm
example/package.json
  • parcel ^2.2.0
  • posthtml-parser ^0.11.0
package.json
  • @babel/runtime ^7.16.7
  • @parcel/plugin ^2.2.0
  • @types/marked ^5.0.0
  • marked ^5.0.0
  • @parcel/config-default ^2.3.2
  • @parcel/core ^2.3.2
  • tsbb ^4.1.5
  • parcel ^2.2.0
  • node >= 18.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Markdown with JS code block breaks with template literal interpolation

code.md (remove blackslash \)

\`\`\`js
const age = 100
const str = `Hello, I am ${age} years old.`
\`\`\`

index.js

import code from './code.md'

index.html

<script src="index.js"></script>

package.json

"scripts": {
  "start": "parcel index.html"
}

Uncaught ReferenceError: age is not defined

Settings required to convert from markdown to html

Hi, there

I have installed parcel-plugin-markdown-string, what are required settings to convert from markdown file into html file ?

Please guide, thanks

Output

package.json

{
  "devDependencies": {
    "parcel-plugin-markdown-string": "^1.3.2"
  }
}

index.md

### Overview

Lorem ipsum dolor sit amet consectetur adipisicing elit. Pariatur libero accusantium aut maxime, sequi, facere, exercitationem quos ipsa dolore placeat quam. Error nemo cum quaerat provident dolores, excepturi debitis repellendus.

### Links

[google.com]('https://google.com')

index.js

import html from './index.md'
console.log(html)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.