Comments (4)
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.
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.
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.
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)
- Live Demo is very out of date
- How do block parsers work?!
- CommonMark discrepancy - handling of HTML tags HOT 1
- Is there any progress on this issue?
- Option to disable images
- Cannot use `CTRL+C` to copy selected text in preview HOT 2
- How does one extend built-in parsers/tokenizers?
- decodeEntity failing in react-native works well in web HOT 1
- way to ignore unclosed codeblocks
- WebComponents not working and nested block not regarded HOT 2
- Update highlight.js example to latest version.
- [High Severity] Authentication Bypass by Spoofing detects in dependency package `[email protected]` HOT 1
- Failed to parse source map
- Lists markers rendered on preceding line
- Image for sponsorships
- want to help maintain Remarkable? HOT 1
- Mac desktop app - export pdf HOT 2
- How to extend this lib to support table cells merge? HOT 1
- How to support HTML Comments?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remarkable.