Giter Club home page Giter Club logo

Comments (4)

wooorm avatar wooorm commented on May 28, 2024 1

This isn’t really an issue with remark-breaks, so I’ll close this.

Ignoring them is indeed part of Markdown, and the CM spec. It’s not something I’m interested in adding.

It’s indeed possible to do basically anything in userland, glad you found something!

micromark, which is getting close, will have lineEndingBlank tokens, part of the CST, which you could compile to persists in Markdown or HTML

from remark-breaks.

wooorm avatar wooorm commented on May 28, 2024 1
| th       |
| -------- |
| td<br>td |

Also: please ask questions in the correct places.

from remark-breaks.

safareli avatar safareli commented on May 28, 2024

Something like this worked for me

// adopted from
// https://github.com/remarkjs/remark/blob/fbbc3a9cfc66441d05234857b8241a46a077e6e7/packages/remark-parse/lib/tokenize/blank-line.js
import {
  Settings,
  Processor,
  ParserConstructor,
  ParserFunction,
} from "unified/types";
import { Node } from "unist";

const reBlankLine = /^[ \t]*(\n|$)/;

export function blankLines(this: Processor<Settings>) {
  const parser = this.Parser;

  if (!isRemarkParser(parser)) {
    throw new Error("Missing parser to attach `blankLines` to");
  }

  parser.prototype.blockTokenizers.blankLine = blankLine;
  // NOTE [email protected] we use depends on [email protected]  while we use [email protected]
  if (parser.prototype.blockMethods.indexOf("blankLine") === -1) {
    parser.prototype.blockMethods.unshift("blankLine");
  }

  function blankLine(
    this: Tokenizer,
    eat: (consumed: string) => (node: Node) => void,
    value: string,
    silent: boolean
  ): true | void {
    let index = 0;
    const length = value.length;
    let eatenLines = 0;
    while (index < length) {
      const match = reBlankLine.exec(value.slice(index));

      if (match == null) {
        break;
      }
      if (silent) {
        return true;
      }
      // debugger;
      const line = match[0];
      index += line.length;

      const add = eat(line);
      // NOTE if we are at start we add break for each line
      // otherwise we ignore first line as it's newline of previous block
      if (this.atStart === true || eatenLines > 0) {
        add({ type: "break" });
      }
      eatenLines++;
    }
  }
}

function isRemarkParser(parser: ParserConstructor | ParserFunction) {
  return (
    parser != null &&
    parser.prototype != null &&
    parser.prototype.blockTokenizers != null
  );
}

type Tokenizer = {
  atStart: boolean;
  inBlock: boolean;
  inLink: boolean;
  inList: boolean;
};

from remark-breaks.

sskanishk avatar sskanishk commented on May 28, 2024

How to break line in table ? ( gfm is enabled )
And md file is imported.
i.e md text is not in same file.

from remark-breaks.

Related Issues (7)

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.