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

Do not process italic syntax on links. #3

Merged
merged 7 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Examples/iOS/Resources/Localizable.strings
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the demo template to showcase more cases (link with underscores and bold+italic vs italic+bold)

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
Created by Ivan Bruel on 19/07/16.
Copyright © 2016 CocoaPods. All rights reserved.
*/
"Markdown" = "** Not bold ** vs **Bold** \n\n _ not italic _ vs _italic_ \n\n **_Italic and bold_** \n\n ~~ not strike ~~ vs ~~strike~~ \n\n * list \n\n * list \n\n + list + \n\n + list 2 + \n\n 1) list \n\n 2) list \n\n + hey \n\n 3) ahah \n\n 1) q2wwe \n\n 2) hey \n\n ([linkme](schema://domain/whees))$321 and more\n\n[linkme](schema://domain/whee()) and more.\n\n[Here](http://example.com/test(1).html)asd asd\n\n[Simple](http://example.com/test.html) aaaa\n\nCode\n\n`this is code` ```this is code too```\n\n Testing (**Bold**) or ( **Bold**)\n\n# Community Rules\n\n## Rule 1: Reddit's site-wide rules\n\n\n**[Click Here](http://www.reddit.com/rules) for reddit's 6 rules.** \n\nThey are all pretty straight forward and easy to understand, but if you would like more information about them [**Click Here**](http://www.reddit.com/wiki/faq) for reddit's Frequently Asked Questions page.\n\n**Be sure to also read [the rediquette](https://www.reddit.com/wiki/reddiquette) which is an informal guide to reddit etiquette.**\n\n_____\n\n##Rule 2: Don't be a jerk\n\n\n**We're here to have a laugh; hate speech, bigotry, and personal attacks are not allowed.**\n\n**Death threats and telling others to kill themselves will result in a ban.**\n\nThis is pretty self explanatory.\n\n_____\n\n\n##Rule 3: Follow the correct format\n\n\n**Two line joke over a re-usable character.** \n\nWe understand that some established memes do not follow this format, such as \n\n* [What Year Is It?](http://knowyourmeme.com/memes/what-year-is-it)\n\n* [I Should Buy a Boat Cat](http://knowyourmeme.com/memes/i-should-buy-a-boat-cat)\n\n* Etc\n\nHowever, these memes are already well established and thus have been grandfathered in.\n\n**Not all image macros are memes**\n\n>Meme -\n\n>/m\u0113m/\n\n>noun\n\n>an element of a culture or system of behavior that may be considered to be passed from one individual to another by nongenetic means, esp. imitation.\n\n>[source](http://www.oxforddictionaries.com/us/definition/american_english/meme)\n\nBasically if the image is only relevant to one's own submission and can't be re-used (or has limited re-usability) then it's just an image macro and by definition not a meme.\n\n* [This is an example of a generic image macro.](https://i.imgur.com/LT1Fi3N.jpg)\n\nand\n\n* [This is an example of a meme.](https://i.imgur.com/871gSb7.jpg)\n\nMemes are allowed on the subreddit here, while generic image macros are better suited for /r/funny. \n\n_____\n\n##Rule 4: Don't repost\n\n**Don't post stuff you found from elsewhere on the web, it's probably been here already.**\n\nThis subreddit is for original content only, meaning memes YOU made. \n\nDo not resubmit your post because it did poorly. \n\nReposting is a bannable offense.\n\nIf you see a repost please report it as such, and [send a quick note to the mods](http://www.reddit.com/message/compose?to=%2Fr%2FAdviceAnimals&subject=I+found+a+repost&message=Here+is+a+link+to+the+comment+section+of+the+repost:%0D%0A%0DAnd+here+is+proof+that+it+is+a+repost:) if you can.\n\n____\n\n##Rule 5: No Cake Day Posts\n\n**Cake Day posts are not allowed.**\n\nPosts that mention Cake Day in the title, or in the post itself will be removed.\n\n____\n\n\n##Rule 6: Verticals, Puffins and Batman Slaps\n\n**Please do not post Verticals, Opinion Puffins or Batman Slaps.**\n\nVerticals are multiple panel memes or image macros and both are better suited for either /r/funny or /r/vertical.\n\n* [This is an example of a vertical meme.](http://i.imgflip.com/bhnki.jpg)\n\n* [This is an example of a vertical image macro](https://i.imgur.com/UrHut.jpg)\n\nThis also means posts such as [9/11 Lois](http://i.imgur.com/DxdSLIo.jpg) aren't allowed; and memes such as [Nobody cares Nedry](http://i.imgur.com/P4KwK1i.jpg) and [Confused Gandalf](http://i.imgur.com/TKujvA3.jpg) are limited to their 1 panel standard, instead of their alternate vertical counterparts.\n\n2 AdviceAnimals in a vertical are OK.\n\nMeaning combining 2 established memes together such as [Socially Awkward Penguin](http://knowyourmeme.com/memes/socially-awkward-penguin) and [Socially Awesome Penguin](http://knowyourmeme.com/memes/socially-awesome-penguin) is fine.\n\n[Here is an example of its acceptable use](https://i.imgur.com/SRYGJdo.jpg)\n\n\n\n\n* [This is unpopular opinion puffin](http://i.imgur.com/qs4z4Rm.jpg)\n\n* [This is an example of a Batman Slap](https://i.imgur.com/5rrb52F.jpg)\n\n_____\n\n\n##Rule 7: Link directly to your image\n\n**Make sure you link directly to your image.**\n\nIn other words, not just to the website, or the gallery page.\n\nHere are a few examples.\n\n* OK.\n\nhttp://i.imgur.com/wdLOqmx.png\n\n\n* Not OK.\n\nhttp://imgur.com/gallery/wdLOqmx\n\nhttp://imgur.com/memegen\n\nhttp://makeameme.org/newest\n\n\n_____\n\n\n##Rule 8: People you know\n\n**Don't make memes with pics of people that you saw in real life. Ever.**\n\nDon't try to make yourself or someone you know into a meme.\n\nAlso, we do not allow witch hunts on the subreddit.\n\n_____\n\n##Rule 9: Use an approved host\n\n**Shortened links, Facebook, Tumblr, Blogspot, etc, will be automatically removed.**\n\nPlease use one of the approved websites listed on the sidebar to make your post.\n\n_____\n\n##Rule 10: Mods have the final say\n\n**We reserve the right to remove posts, remove comments, and ban users at our own discretion.**\n\nDue to the nature of the subreddit, interpretations of what is a meme and what is an image macro sometimes have different opinions and thus decisions have to be made.\n\n_____\n\n\n#[Always feel free to message the moderators if you have ANY questions!](https://www.reddit.com/message/compose?to=%2Fr%2FAdviceAnimals)\n\n Moar code `this is code` ```(this is code too)```";
"Markdown" = "** Not bold ** vs **Bold** \n\n _ not italic _ vs _italic_ \n\n **_Bold and italic_** \n\n _**Italic and bold**_\n\n ~~ not strike ~~ vs ~~strike~~ \n\n * list \n\n * list \n\n + list + \n\n + list 2 + \n\n 1) list \n\n 2) list \n\n + hey \n\n 3) ahah \n\n 1) q2wwe \n\n 2) hey \n\n ([linkme](https://website.com/?user_id=abc&session_id=xyz))$321 and more\n\n[linkme](schema://domain/whee()) and more.\n\n[https://website.com/?user_id=abc&session_id=xyz](https://website.com/?user_id=abc&session_id=xyz)asd asd\n\nhttps://website.com/?user_id=abc&session_id=xyz aaaa\n\nCode\n\n`this is code` ```this is code too```\n\n Testing (**Bold**) or ( **Bold**)\n\n# Community Rules\n\n## Rule 1: Reddit's site-wide rules\n\n\n**[Click Here](http://www.reddit.com/rules) for reddit's 6 rules.** \n\nThey are all pretty straight forward and easy to understand, but if you would like more information about them [**Click Here**](http://www.reddit.com/wiki/faq) for reddit's Frequently Asked Questions page.\n\n**Be sure to also read [the rediquette](https://www.reddit.com/wiki/reddiquette) which is an informal guide to reddit etiquette.**\n\n_____\n\n##Rule 2: Don't be a jerk\n\n\n**We're here to have a laugh; hate speech, bigotry, and personal attacks are not allowed.**\n\n**Death threats and telling others to kill themselves will result in a ban.**\n\nThis is pretty self explanatory.\n\n_____\n\n\n##Rule 3: Follow the correct format\n\n\n**Two line joke over a re-usable character.** \n\nWe understand that some established memes do not follow this format, such as \n\n* [What Year Is It?](http://knowyourmeme.com/memes/what-year-is-it)\n\n* [I Should Buy a Boat Cat](http://knowyourmeme.com/memes/i-should-buy-a-boat-cat)\n\n* Etc\n\nHowever, these memes are already well established and thus have been grandfathered in.\n\n**Not all image macros are memes**\n\n>Meme -\n\n>/m\u0113m/\n\n>noun\n\n>an element of a culture or system of behavior that may be considered to be passed from one individual to another by nongenetic means, esp. imitation.\n\n>[source](http://www.oxforddictionaries.com/us/definition/american_english/meme)\n\nBasically if the image is only relevant to one's own submission and can't be re-used (or has limited re-usability) then it's just an image macro and by definition not a meme.\n\n* [This is an example of a generic image macro.](https://i.imgur.com/LT1Fi3N.jpg)\n\nand\n\n* [This is an example of a meme.](https://i.imgur.com/871gSb7.jpg)\n\nMemes are allowed on the subreddit here, while generic image macros are better suited for /r/funny. \n\n_____\n\n##Rule 4: Don't repost\n\n**Don't post stuff you found from elsewhere on the web, it's probably been here already.**\n\nThis subreddit is for original content only, meaning memes YOU made. \n\nDo not resubmit your post because it did poorly. \n\nReposting is a bannable offense.\n\nIf you see a repost please report it as such, and [send a quick note to the mods](http://www.reddit.com/message/compose?to=%2Fr%2FAdviceAnimals&subject=I+found+a+repost&message=Here+is+a+link+to+the+comment+section+of+the+repost:%0D%0A%0DAnd+here+is+proof+that+it+is+a+repost:) if you can.\n\n____\n\n##Rule 5: No Cake Day Posts\n\n**Cake Day posts are not allowed.**\n\nPosts that mention Cake Day in the title, or in the post itself will be removed.\n\n____\n\n\n##Rule 6: Verticals, Puffins and Batman Slaps\n\n**Please do not post Verticals, Opinion Puffins or Batman Slaps.**\n\nVerticals are multiple panel memes or image macros and both are better suited for either /r/funny or /r/vertical.\n\n* [This is an example of a vertical meme.](http://i.imgflip.com/bhnki.jpg)\n\n* [This is an example of a vertical image macro](https://i.imgur.com/UrHut.jpg)\n\nThis also means posts such as [9/11 Lois](http://i.imgur.com/DxdSLIo.jpg) aren't allowed; and memes such as [Nobody cares Nedry](http://i.imgur.com/P4KwK1i.jpg) and [Confused Gandalf](http://i.imgur.com/TKujvA3.jpg) are limited to their 1 panel standard, instead of their alternate vertical counterparts.\n\n2 AdviceAnimals in a vertical are OK.\n\nMeaning combining 2 established memes together such as [Socially Awkward Penguin](http://knowyourmeme.com/memes/socially-awkward-penguin) and [Socially Awesome Penguin](http://knowyourmeme.com/memes/socially-awesome-penguin) is fine.\n\n[Here is an example of its acceptable use](https://i.imgur.com/SRYGJdo.jpg)\n\n\n\n\n* [This is unpopular opinion puffin](http://i.imgur.com/qs4z4Rm.jpg)\n\n* [This is an example of a Batman Slap](https://i.imgur.com/5rrb52F.jpg)\n\n_____\n\n\n##Rule 7: Link directly to your image\n\n**Make sure you link directly to your image.**\n\nIn other words, not just to the website, or the gallery page.\n\nHere are a few examples.\n\n* OK.\n\nhttp://i.imgur.com/wdLOqmx.png\n\n\n* Not OK.\n\nhttp://imgur.com/gallery/wdLOqmx\n\nhttp://imgur.com/memegen\n\nhttp://makeameme.org/newest\n\n\n_____\n\n\n##Rule 8: People you know\n\n**Don't make memes with pics of people that you saw in real life. Ever.**\n\nDon't try to make yourself or someone you know into a meme.\n\nAlso, we do not allow witch hunts on the subreddit.\n\n_____\n\n##Rule 9: Use an approved host\n\n**Shortened links, Facebook, Tumblr, Blogspot, etc, will be automatically removed.**\n\nPlease use one of the approved websites listed on the sidebar to make your post.\n\n_____\n\n##Rule 10: Mods have the final say\n\n**We reserve the right to remove posts, remove comments, and ban users at our own discretion.**\n\nDue to the nature of the subreddit, interpretations of what is a meme and what is an image macro sometimes have different opinions and thus decisions have to be made.\n\n_____\n\n\n#[Always feel free to message the moderators if you have ANY questions!](https://www.reddit.com/message/compose?to=%2Fr%2FAdviceAnimals)\n\n Moar code `this is code` ```(this is code too)```";
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

open class MarkdownItalic: MarkdownCommonElement {

fileprivate static let regex = "(.?|^)(\\*|_)(?=\\S)(.+?)(?<![\\*_\\s])(\\2)"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This regex was implemented in bmoliveira@761a30e to "fix" when the italic syntax is combined with bold and/or other characters, but it was capturing the preceding character (e.g., when capturing _italic_, it would capture _italic_ with the space before. I reverted it as it doesn't make much sense for our use case, and it still works with bold text.

fileprivate static let regex = "(\\s|^)(\\*|_)(?=\\S)(.+?)(?<![\\*_\\s])(\\2)"

open var font: MarkdownFont?
open var color: MarkdownColor?
Expand Down
2 changes: 1 addition & 1 deletion MarkdownKit/Sources/Common/MarkdownParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ open class MarkdownParser {
(.bold, bold),
(.italic, italic),
(.strikethrough, strikethrough),
(.link, link),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the link was being parsed before, it would join the text coming after the link, and the autolink would incorrectly make the following text a part of the link.

(.automaticLink, automaticLink),
(.link, link),
(.code, code),
]
defaultElements = pairs.compactMap { enabled, element in
Expand Down
Loading