🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@codemirror/lang-markdown

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codemirror/lang-markdown - npm Package Compare versions

Comparing version
6.3.4
to
6.4.0
+6
-0
CHANGELOG.md

@@ -0,1 +1,7 @@

## 6.4.0 (2025-10-02)
### New features
The new `pasteURLAsLink` extension allows you to paste URLs over a selection to quickly create a link.
## 6.3.4 (2025-08-01)

@@ -2,0 +8,0 @@

+43
-1

@@ -400,3 +400,3 @@ 'use strict';

function markdown(config = {}) {
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true, htmlTagLanguage = htmlNoMatch } = config;
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true, pasteURLAsLink: pasteURL = true, htmlTagLanguage = htmlNoMatch } = config;
if (!(parser instanceof markdown$1.MarkdownParser))

@@ -406,2 +406,4 @@ throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");

let support = [htmlTagLanguage.support, headerIndent], defaultCode;
if (pasteURL)
support.push(pasteURLAsLink);
if (defaultCodeLanguage instanceof language.LanguageSupport) {

@@ -447,2 +449,41 @@ support.push(defaultCodeLanguage.support);

}
const nonPlainText = /code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i;
/**
An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.
*/
const pasteURLAsLink = view.EditorView.domEventHandlers({
paste: (event, view) => {
var _a;
let { main } = view.state.selection;
if (main.empty)
return false;
let link = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData("text/plain");
if (!link || !/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(link))
return false;
if (/^www\./.test(link))
link = "https://" + link;
if (!markdownLanguage.isActiveAt(view.state, main.from, 1))
return false;
let tree = language.syntaxTree(view.state), crossesNode = false;
// Verify that no nodes are started/ended between the selection
// points, and we're not inside any non-plain-text construct.
tree.iterate({
from: main.from, to: main.to,
enter: node => { if (node.from > main.from || nonPlainText.test(node.name))
crossesNode = true; },
leave: node => { if (node.to < main.to)
crossesNode = true; }
});
if (crossesNode)
return false;
view.dispatch({
changes: [{ from: main.from, insert: "[" }, { from: main.to, insert: `](${link})` }],
userEvent: "input.paste",
scrollIntoView: true
});
return true;
}
});

@@ -455,1 +496,2 @@ exports.commonmarkLanguage = commonmarkLanguage;

exports.markdownLanguage = markdownLanguage;
exports.pasteURLAsLink = pasteURLAsLink;

@@ -0,5 +1,6 @@

import * as _codemirror_state from '@codemirror/state';
import { StateCommand } from '@codemirror/state';
import { KeyBinding } from '@codemirror/view';
import { Language, LanguageSupport, LanguageDescription } from '@codemirror/language';
import { MarkdownExtension } from '@lezer/markdown';
import { StateCommand } from '@codemirror/state';

@@ -89,2 +90,8 @@ /**

/**
The returned language contains
[`pasteURLAsLink`](https://codemirror.net/6/docs/ref/#lang-markdown.pasteURLAsLink) as a support
extension unless you set this to false.
*/
pasteURLAsLink?: boolean;
/**
By default, HTML tags in the document are handled by the [HTML

@@ -97,3 +104,9 @@ language](https://github.com/codemirror/lang-html) package with

}): LanguageSupport;
/**
An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.
*/
declare const pasteURLAsLink: _codemirror_state.Extension;
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage };
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage, pasteURLAsLink };

@@ -0,5 +1,6 @@

import * as _codemirror_state from '@codemirror/state';
import { StateCommand } from '@codemirror/state';
import { KeyBinding } from '@codemirror/view';
import { Language, LanguageSupport, LanguageDescription } from '@codemirror/language';
import { MarkdownExtension } from '@lezer/markdown';
import { StateCommand } from '@codemirror/state';

@@ -89,2 +90,8 @@ /**

/**
The returned language contains
[`pasteURLAsLink`](https://codemirror.net/6/docs/ref/#lang-markdown.pasteURLAsLink) as a support
extension unless you set this to false.
*/
pasteURLAsLink?: boolean;
/**
By default, HTML tags in the document are handled by the [HTML

@@ -97,3 +104,9 @@ language](https://github.com/codemirror/lang-html) package with

}): LanguageSupport;
/**
An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.
*/
declare const pasteURLAsLink: _codemirror_state.Extension;
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage };
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage, pasteURLAsLink };
import { EditorSelection, countColumn, Prec, EditorState } from '@codemirror/state';
import { keymap } from '@codemirror/view';
import { EditorView, keymap } from '@codemirror/view';
import { defineLanguageFacet, foldNodeProp, indentNodeProp, languageDataProp, foldService, syntaxTree, Language, LanguageDescription, ParseContext, indentUnit, LanguageSupport } from '@codemirror/language';

@@ -398,3 +398,3 @@ import { CompletionContext } from '@codemirror/autocomplete';

function markdown(config = {}) {
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true, htmlTagLanguage = htmlNoMatch } = config;
let { codeLanguages, defaultCodeLanguage, addKeymap = true, base: { parser } = commonmarkLanguage, completeHTMLTags = true, pasteURLAsLink: pasteURL = true, htmlTagLanguage = htmlNoMatch } = config;
if (!(parser instanceof MarkdownParser))

@@ -404,2 +404,4 @@ throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");

let support = [htmlTagLanguage.support, headerIndent], defaultCode;
if (pasteURL)
support.push(pasteURLAsLink);
if (defaultCodeLanguage instanceof LanguageSupport) {

@@ -445,3 +447,42 @@ support.push(defaultCodeLanguage.support);

}
const nonPlainText = /code|horizontalrule|html|link|comment|processing|escape|entity|image|mark|url/i;
/**
An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.
*/
const pasteURLAsLink = /*@__PURE__*/EditorView.domEventHandlers({
paste: (event, view) => {
var _a;
let { main } = view.state.selection;
if (main.empty)
return false;
let link = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData("text/plain");
if (!link || !/^(https?:\/\/|mailto:|xmpp:|www\.)/.test(link))
return false;
if (/^www\./.test(link))
link = "https://" + link;
if (!markdownLanguage.isActiveAt(view.state, main.from, 1))
return false;
let tree = syntaxTree(view.state), crossesNode = false;
// Verify that no nodes are started/ended between the selection
// points, and we're not inside any non-plain-text construct.
tree.iterate({
from: main.from, to: main.to,
enter: node => { if (node.from > main.from || nonPlainText.test(node.name))
crossesNode = true; },
leave: node => { if (node.to < main.to)
crossesNode = true; }
});
if (crossesNode)
return false;
view.dispatch({
changes: [{ from: main.from, insert: "[" }, { from: main.to, insert: `](${link})` }],
userEvent: "input.paste",
scrollIntoView: true
});
return true;
}
});
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage };
export { commonmarkLanguage, deleteMarkupBackward, insertNewlineContinueMarkup, markdown, markdownKeymap, markdownLanguage, pasteURLAsLink };
+1
-1
{
"name": "@codemirror/lang-markdown",
"version": "6.3.4",
"version": "6.4.0",
"description": "Markdown language support for the CodeMirror code editor",

@@ -5,0 +5,0 @@ "scripts": {

@@ -81,2 +81,8 @@ <!-- NOTE: README.md is generated from src/README.md -->

disable this.</p>
</dd><dt id="user-content-markdown^config.pasteurlaslink">
<code><strong><a href="#user-content-markdown^config.pasteurlaslink">pasteURLAsLink</a></strong>&#8288;?: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></dt>
<dd><p>The returned language contains
<a href="#user-content-pasteurlaslink"><code>pasteURLAsLink</code></a> as a support
extension unless you set this to false.</p>
</dd><dt id="user-content-markdown^config.htmltaglanguage">

@@ -133,2 +139,9 @@ <code><strong><a href="#user-content-markdown^config.htmltaglanguage">htmlTagLanguage</a></strong>&#8288;?: <a href="https://codemirror.net/docs/ref#language.LanguageSupport">LanguageSupport</a></code></dt>

</dd>
<dt id="user-content-pasteurlaslink">
<code><strong><a href="#user-content-pasteurlaslink">pasteURLAsLink</a></strong>: <a href="https://codemirror.net/docs/ref#state.Extension">Extension</a></code></dt>
<dd><p>An extension that intercepts pastes when the pasted content looks
like a URL and the selection is non-empty and selects regular
text, making the selection a link with the pasted URL as target.</p>
</dd>
</dl>