Giter Site home page Giter Site logo

remarkjs / strip-markdown Goto Github PK

View Code? Open in Web Editor NEW
125.0 10.0 23.0 511 KB

plugin remove Markdown formatting

Home Page: http://remarkjs.github.io/strip-markdown

License: MIT License

JavaScript 100.00%
remark remark-plugin markdown strip clean remove

strip-markdown's People

Contributors

greenkeeperio-bot avatar janosh avatar ohtake avatar samuelmeuli avatar stefanprobst avatar tusbar 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  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  avatar

strip-markdown's Issues

Option to keep list characters

Subject of the feature

Option to keep list characters

Problem

I'm using this module for a feature for exporting Markdown to TXT. Unfortunately, after processing the MD with this plugin, lists are no longer recognizable as such because the list characters (e.g. - ) are removed.

Expected behaviour

I understand that removing this information is what the plugin is supposed to do. For my use case, however, it would be nice to have an option to keep these list characters in the output.

I completely understand if this is not something you'd like to integrate or if you'd rather not provide options for the plugin. If so, feel free to close this issue :)

Fix exception for parents without children

Subject of the issue

When strip-markdown encounters a link node without children, it throws Cannot use 'in' operator to search for 'length' in undefined. This is because mapFiltered.link expects node.children.

Your environment

Steps to reproduce

const unified = require('unified')
const strip = require('strip-markdown')

const ast = {
  type: 'root',
  children: [
    {
      type: 'link',
      url: '#hash-link',
      title: null,
      data: {
        hProperties: {
          'aria-label': 'some info',
          class: 'anchor'
        },
        hChildren: [
          {
            type: 'raw',
            value: '<svg></svg>'
          }
        ]
      }
    }
  ]
}

unified()
  .use(strip)
  .runSync(ast)

Expected behaviour

Don't crash

Actual behaviour

Crash

HTML in Markdown

Subject of the issue

Strings starting with <p>...</p> cause everything else to be dropped.

remark()
  .use(strip)
  .process('<p>foo</p> bar', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Actual: ""
Expected: "foo bar"

With some text before the tag, it works as expected:

remark()
  .use(strip)
  .process('foo <p>bar</p>', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Actual: "foo bar"

Your environment

  • OS: macOS 10.15.5
  • Packages: strip-markdown "3.1.2"
  • Env: node 14

Steps to reproduce

The issue can also be reproduced on the demo, just enter:

<p>foo</p>
bar

Expected behavior

<p> tag should be stripped and the inner text should be returned. This behavior works with other tags like <span>.

Actual behavior

<p>foo</p> bar returns an empty string, but foo <p>bar</p> returns "foo bar".

Not working with current mdast?

Just followed the demo at README:

var strip = require('strip-markdown');
var mdast = require('mdast').use(strip);

var ast = mdast.parse('Some *emphasis*, **strongness**, and `code`.');
var doc = mdast.stringify(ast);

console.log(doc);

That yields Some _emphasis_, **strongness**, andcode.. Any idea why?

Keep existing new lines when thematic breaks are removed

Initial checklist

Problem

Currently, when headings are removed, the text is just concatenated.
Edit: Sorry, this might actually be a bug. It only happens if there are thematicBreaks and they are being removed (default).

Example:

# Foo

## Bar

---

## Testing

becomes

FooBarTesting

Solution

I'm not sure exactly, I will investigate.

Alternatives

Add remark as peer dependency

This is not exactly a feature btw

Hey! Since this lib is a plugin to another one (remark) it would be nice to put remark as a peer dependecy thus users will be aware of which version of remark is supported ^^

basically npm install --save-peer remark@^13.0.0

Backslash prepended to the input `[`

Initial checklist

Affected packages and versions

[email protected], [email protected]

Link to runnable example

No response

Steps to reproduce

  1. Go to the playground: http://remarkjs.github.io/strip-markdown/
  2. Enter [

Expected behavior

The output is [.

Actual behavior

The output is \[.

I am not sure if this is intentional escaping or a bug.

I have a string of Markdown, and I want to convert it to plain text. With the current behavior, I will end up displaying backslashes that were not in the original text.

Runtime

Node v16

Package manager

yarn 2

OS

macOS

Build and bundle tools

Other (please specify in steps to reproduce)

Add typescript types

Subject of the feature

Typescript support

Problem

No typing support for this module :(

Type definitions

First of all, thanks a lot for the work on Remark!

I've seen that Remark now has TypeScript definitions included since the latest release. It would be great if they could also be added to this plugin :)

* is converted to \* when trying to strip markdown?

Initial checklist

Affected packages and versions

remark: 15.0.1, strip-markdown: 6.0.0

Link to runnable example

No response

Steps to reproduce

Run the following code remark().use(strip).processSync("Testing*").toString().trimEnd()
I'm using Node 20 and npm 10.2.4 and the code was run in Chrome 123.0.6312.107

Expected behavior

the result should be Testing*

Actual behavior

The result is Testing\*

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

Windows

Build and bundle tools

Vite

Comments cause entire line to be dropped

Seems like HTML comments should just be stripped, but instead putting one on a line causes that entire line to be ignored. I couldn't really tell if this was a bug in the parser or the strip plugin - hope I guessed correctly ;)

Here's a testcase:

'use strict';

const strip = require('strip-markdown'),
      remark = require('remark'),
      processor = remark().use(strip);

const body = '<!-- comment -->foobar'; // It doesn't matter if there's a space before `foobar`

const plaintext = String(processor.processSync(body));

console.log(plaintext); // should be "foobar" but is "" instead

Version information:

% node -v
v4.8.0

% npm ls remark strip-markdown
[email protected] /Users/alex/Development/HTTPS-Everywhere/utils/issue-format-bot
├── [email protected]
└── [email protected]

Thanks for maintaining remark <3

Does not seem to remove tables

var remark = require('remark')
var strip = require('strip-markdown')

remark()
  .use(strip)
  .process('|a|s||-|-||a|a|', function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Type error when using `strip-markdown` in `unified`

Initial checklist

Affected packages and versions

6.0.0

Link to runnable example

No response

Steps to reproduce

node v21.7.3

unified()
  // ...
  .use(stripMarkdown)
  // ...

Expected behavior

No type error

Actual behavior

No overload matches this call.
  Overload 1 of 3, '(preset?: Preset | null | undefined): Processor<Root, undefined, undefined, undefined, undefined>', gave the following error.
    Type '(options?: Readonly<Options> | null | undefined) => (tree: Root) => Root' has no properties in common with type 'Preset'.
  Overload 2 of 3, '(list: PluggableList): Processor<Root, undefined, undefined, undefined, undefined>', gave the following error.
    Argument of type '(options?: Readonly<Options> | null | undefined) => (tree: Root) => Root' is not assignable to parameter of type 'PluggableList'.
  Overload 3 of 3, '(plugin: Plugin<[], Root, Root>, ...parameters: [] | [boolean]): Processor<Root, undefined, undefined, Root, Root>', gave the following error.
    Argument of type '(options?: Readonly<Options> | null | undefined) => (tree: Root) => Root' is not assignable to parameter of type 'Plugin<[], Root, Root>'.
      Type '(tree: Root) => Root' is not assignable to type 'void'.ts(2769)

It seems like the .use(...) method wants the plugin to return nothing (void). Passing stripMarkdown as () => void fixes the type error

Runtime

Other (please specify in steps to reproduce)

Package manager

pnpm

OS

macOS

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.