mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Koenig - Improve link text expansion matching
refs https://github.com/TryGhost/Ghost/issues/9505 - tightens up regex to ensure we're not matching unexpected chars earlier in the paragraph
This commit is contained in:
parent
1a2e345957
commit
8f135264dc
1 changed files with 6 additions and 9 deletions
|
@ -8,9 +8,6 @@ import {run} from '@ember/runloop';
|
||||||
// the matches with additional markup, atoms, or cards
|
// the matches with additional markup, atoms, or cards
|
||||||
// https://github.com/bustlelabs/mobiledoc-kit#responding-to-text-input
|
// https://github.com/bustlelabs/mobiledoc-kit#responding-to-text-input
|
||||||
|
|
||||||
// TODO: this was copied from our old Koenig editor, it could do with some
|
|
||||||
// comments, cleanup, and refactoring
|
|
||||||
|
|
||||||
export default function (editor, koenig) {
|
export default function (editor, koenig) {
|
||||||
// We don't want to run all our content rules on every text entry event,
|
// We don't want to run all our content rules on every text entry event,
|
||||||
// instead we check to see if this text entry event could match a content
|
// instead we check to see if this text entry event could match a content
|
||||||
|
@ -224,11 +221,11 @@ export default function (editor, koenig) {
|
||||||
|
|
||||||
function matchLink(editor, text) {
|
function matchLink(editor, text) {
|
||||||
let {range} = editor;
|
let {range} = editor;
|
||||||
let matches = text.match(/(^|[^!])\[(.*?)\]\((.*?)\)$/);
|
let matches = text.match(/(?:^|\s)\[([^\s\]]+|[^\s\]][^\]]*[^\s\]])\]\(([^\s)]+|[^\s)][^)]*[^\s)])\)/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let url = matches[3];
|
let url = matches[2];
|
||||||
let text = matches[2];
|
let text = matches[1] || url;
|
||||||
let match = matches[0][0] === '[' ? matches[0] : matches[0].substr(1);
|
let match = matches[0].trim();
|
||||||
range = range.extend(-match.length);
|
range = range.extend(-match.length);
|
||||||
|
|
||||||
editor.run((postEditor) => {
|
editor.run((postEditor) => {
|
||||||
|
@ -248,8 +245,8 @@ export default function (editor, koenig) {
|
||||||
let matches = text.match(/^!\[(.*?)\]\((.*?)\)$/);
|
let matches = text.match(/^!\[(.*?)\]\((.*?)\)$/);
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let {range: {head, head: {section}}} = editor;
|
let {range: {head, head: {section}}} = editor;
|
||||||
let src = matches[2];
|
let src = matches[2].trim();
|
||||||
let alt = matches[1];
|
let alt = matches[1].trim();
|
||||||
|
|
||||||
// skip if cursor is not at end of section
|
// skip if cursor is not at end of section
|
||||||
if (!head.isTail()) {
|
if (!head.isTail()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue