GithubHelp home page GithubHelp logo

Comments (4)

jpribyl avatar jpribyl commented on June 11, 2024

I also just ran into this issue. Use case here is if you're trying to do something like adding a hashtag mention plugin. Plenty of workarounds, but feels weird to require a break on @ when the real character you want is #

from remarkable.

TimLaue91 avatar TimLaue91 commented on June 11, 2024

I ran into this problem trying to implement iaWriter-style image links (just beginning with a slash, like '/myImage.jpeg'). I went with the workaround suggested by @knubie, which works, but feels bad:

const md = new Remarkable();

const parse = function(state: Remarkable.StateInline) {
  // Parse...
};

// Part 1 of the hack (taken from text.js and adjusted)
function isTerminatorChar(ch: number) {
  switch (ch) {
    case 0x0A/* \n */:
    case 0x5C/* \ */:
    case 0x2F/* / */:  // Added this line to make '/' a terminator character
    case 0x60/* ` */:
    case 0x2A/* * */:
    case 0x5F/* _ */:
    case 0x5E/* ^ */:
    case 0x5B/* [ */:
    case 0x5D/* ] */:
    case 0x21/* ! */:
    case 0x26/* & */:
    case 0x3C/* < */:
    case 0x3E/* > */:
    case 0x7B/* { */:
    case 0x7D/* } */:
    case 0x24/* $ */:
    case 0x25/* % */:
    case 0x40/* @ */:
    case 0x7E/* ~ */:
    case 0x2B/* + */:
    case 0x3D/* = */:
    case 0x3A/* : */:
      return true;
    default:
      return false;
  }
}

// Part 2 of the hack (taken from text.js, unchanged)
function text(state: Remarkable.StateInline, silent: boolean) {
  var pos = state.pos;
  while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) {
    pos++;
  }
  if (pos === state.pos) { return false; }
  if (!silent) { state.pending += state.src.slice(state.pos, pos); }
  state.pos = pos;
  return true;
};

const myPlugin = function(md: Remarkable) {
  const options = {};
  md.inline.ruler.at('text', text, options)  // Replace default text parser with adjusted one
  md.inline.ruler.push('myPlugin', parse, options);
};

md.use(myPlugin);

Edit: Added correct type annotations.

from remarkable.

DiscoNova avatar DiscoNova commented on June 11, 2024

function text(state: {[key: string]: any}, silent: boolean) {

Holeymoley... that looks like TypeScript - can we do that these days? Have I missed something?

from remarkable.

TimLaue91 avatar TimLaue91 commented on June 11, 2024

I'm afraid I don't understand your question.

If you mean the incrdibly general type annotation: I didn't find a matching type definition in the Remarkable package and I was too lazy to spell out the properties of the state object. I'm also very new to Typescript.

Edit: Added correct type annotation.

from remarkable.

Related Issues (20)

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.