Giter Club home page Giter Club logo

rehype-remark's People

Contributors

171h avatar cbush avatar christianmurphy avatar jounqin avatar sethvincent avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar

rehype-remark's Issues

Types

Can I sponsor some typescript types for this project?

search in hast node

Subject of the feature

Util to search for a hast element, ideally a CSS-like selector

Problem

I would like to try convert only the content of a page, starting at <main>, <article> or [role="main"] and ignore the rest

Expected behaviour

I have implemented a very basic search function (kindof getElementsByTagName), but wonder if
A) this is the right approach
B) if there is already something for HAST (in rehype, unfidied world)

Alternatives

const unified = require('unified')
const createStream = require('unified-stream')
const parse = require('rehype-parse')
const rehype2remark = require('rehype-remark')
const stringify = require('remark-stringify')
// note:
const all = require('hast-util-to-mdast/lib/all')
const wrap = require('hast-util-to-mdast/lib/util/wrap')

const processor = unified()
  .use(parse)
  .use(rehype2remark, { handlers: { body }}) // changes the body
  .use(stringify)

// try to use main or article, else fallback to body 
function body(h, node) {
  return wrap(all(h, search(node, 'main, article') || node))
}

process.stdin.pipe(createStream(processor)).pipe(process.stdout)

// returns first node by tagName
function search(node, tagName) {
  const tagNames = tagName.split(',').map(s => s.trim())
  const que = node.children
  for (const node of que) {
    if (node.type === 'element' && tagNames.includes(node.tagName)) {
      return node
    }
    if (node.children && node.children.length) {
      que.push(...node.children)
    }
  }
  return null
}

Incorrect bold parsing in CJK on Markdown

Initial checklist

Affected packages and versions

latest

Link to runnable example

No response

Steps to reproduce

Convert following html to remark

<strong>
Hello Gamer
</strong>

it will be failed to be strong in markdown.

Expected behavior

Hello Gamer

Actual behavior

**Hello Gamer **

Runtime

Node v16

Package manager

yarn 1

OS

Windows

Build and bundle tools

No response

9.1.1 cannot import lib/index.js

Initial checklist

Affected packages and versions

9.1.1

Link to runnable example

No response

Steps to reproduce

You can see what it is erroring out here: https://cdn.skypack.dev/[email protected] and the error message from skypack here: https://cdn.skypack.dev/error/build:[email protected]

This is also happening when trying to use the package locally

Expected behavior

We should be able to import the library without any issues

Actual behavior

The lib directory doesn't look to be built so when we try and import the package it's looking for a file that doesn't exist and errors.

Runtime

Node v16

Package manager

npm v7

OS

macOS

Build and bundle tools

No response

9.1.0 is not released

Initial checklist

Affected packages and versions

9.1.0

Link to runnable example

https://www.npmjs.com/package/rehype-remark

Steps to reproduce

https://www.npmjs.com/package/rehype-remark/v/9.1.0

Expected behavior

release 9.1.0 to npm

Actual behavior

not released

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

Retain Props on html nodes

Subject of the feature

Retain Props on html nodes
OR
don't convert elements with props

Problem

I have been building a markdown editor, for use creating an e-learning platform.

I've utilised Remark and Rehype to create and sanitise both markdown and html within the same document, for flexibility purposes. As an example, I am able to add embedded video players, more customisable tables, safer links etc, but only when required - generally we use markdown for simplicity.

This is all working as expected, with one exception: additional props to html elements -> they are converted back to standard markdown elements.

For example, if I added a open="_blank" and rel="noreferrer" properties to an A tag, this would be stripped when converted to remark using rehype-remark.

Code is as follows:

import remark from 'remark'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeRaw from 'rehype-raw'
import rehypeSanitize from 'rehype-sanitize'
import rehypeRemark from 'rehype-remark'

const markdownTagNames = ['a', 'p', 'h1']

const markdown = `
# header

<a href="https://github.com/rehypejs/rehype-remark" open="_blank" rel="noreferrer">rehype-remark link (new tab)</a>
`

 remark()
            .use(remarkParse)
            .use(remarkRehype, { allowDangerousHtml: true })
            .use(rehypeRaw)
            .use(rehypeSanitize, { tagNames: markdownTagNames })
            .use(rehypeRemark)
            .processSync(markdown).contents;

This outputs:

# header

[rehype-remark link (new tab)](https://github.com/rehypejs/rehype-remark)

Expected behavior

Rehype documents containing markdown convertible-nodes should only convert if no properties exist.

Alternatives

  1. A white/black-list config approach to nodes may be a round-about way of ensuring these props exist still
  2. Some sort of indicator/property to add so the conversion process only needs to check for the presence of one field

Workarounds

The main reason I was trying to convert the rehype back to remark was to save the sanitised input, rather than the markdown with tags in the .md file, and sanitize every time they're presented.

In the mean-time, there are two workarounds:

saving the unsanitised .md files
This could contain <script> tags for example, but sanitizing them upon presentation.

The main risk of this approach would be forgetting to sanitize the document.

Injecting open/noreferrer to all a tags on the presentation layer
A bit carte blanche, but resolves the pen-test issue.

Creating a separate node for custom conversion
More a theory, but possibly the most abstract way of doing it. This would result in having non common markup options though.

Problem when HTML contains `&`

Initial checklist

Affected packages and versions

rehype-remark 9.1.2, remark-stringify 10.0.2, rehype-parse 8.0.4

Link to runnable example

No response

Steps to reproduce

import rehypeParse from 'rehype-parse';
import rehypeRemark from 'rehype-remark';
import remarkStringify from 'remark-stringify';

main();

async function main() {
  const file = unified()
      .use(rehypeParse)
      .use(rehypeRemark)
      .use(remarkStringify)
      .processSync('<h1>Q&A</h1>');

  console.log(String(file));
}

Expected behavior

The output should be # Q&A

Actual behavior

The output is # Q\&A
Looking at the generated string it looks like #Q\\&A instead of #Q\&A

Runtime

Node v16

Package manager

npm 8

OS

macOS

Build and bundle tools

No response

Invalid markdown produced due to spacing

Initial checklist

Affected packages and versions

10

Link to runnable example

No response

Steps to reproduce

This was originally observed in the wild while copying text from nytimes.com

Expected behavior

Valid markdown output.

Actual behavior

Invalid markdown output.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

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.