Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

morebits: Ignore file/category embeds when removing links #239

Merged
merged 1 commit into from Sep 4, 2018

Conversation

kevinji
Copy link
Collaborator

@kevinji kevinji commented Aug 5, 2014

Fixes #231. @atlight Could I get a second pair of eyes on that regex? I'm pretty sure it's correct but I might have made a simple mistake.

morebits.js Outdated
@@ -2999,10 +2999,11 @@ Morebits.wikitext.page = function mediawikiPage( text ) {
Morebits.wikitext.page.prototype = {
text: '',
removeLink: function( link_target ) {
var not_link_re_string = "(?!(?:[Ff]ile|[Ii]mage|[Cc]ategory):)";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test it (no time right now...), but it seems that JavaScript doesn't support lookbehinds. In any case ?! is a lookahead, not a lookbehind. Could you test this anyway in a browser and see what happens?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't think what I just wrote has much sense. @Amalthea @azatoth how good are you guys at regex? Probably better than me...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a lookahead, which is what I wanted. I'll try to test this in a bit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance this can be constructed from wgNamespaceIds? For the sake of l10n...

@QEDK
Copy link
Contributor

QEDK commented Feb 22, 2015

You could ask Magioalditis or even Reaper Eternal (since RE made many edit filters with regexes).

File: and Category: links (without a leading colon) should not be
removed. Fixes #231.
@kevinji kevinji changed the title morebits: Ignore image/category embeds while removing links morebits: Ignore file/category embeds when removing links Sep 4, 2018
@kevinji
Copy link
Collaborator Author

kevinji commented Sep 4, 2018

I've finally come back to this with a simpler solution (no lookaheads!).

@kevinji kevinji merged commit 83fff83 into master Sep 4, 2018
@kevinji kevinji deleted the morebits-wikitext branch September 4, 2018 00:43
Siddhartha-Ghai pushed a commit to Siddhartha-Ghai/twinkle that referenced this pull request Jan 3, 2019
…gadgets#239)

File: and Category: links (without a leading colon) should not be
removed. Fixes wikimedia-gadgets#231.

(cherry picked from commit 83fff83)
@Amorymeltzer Amorymeltzer added Module: morebits The morebits.js library Module: unlink labels Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: morebits The morebits.js library Module: unlink
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Morebits.wikitext doesn't know that [[File:]] [[Category:]] syntax are special
5 participants