Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

add support for text links with markdown syntax #1766

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

acran
Copy link
Contributor

@acran acran commented Oct 14, 2018

this adds support for easily entering text links - i.e. messageEntityTextUrl text entities - using markdown syntax, i.e.

see the [webogram source](https://github.com/zhukov/webogram/) online

becomes

see the webogram source online

discussion: should we maybe use a slightly different syntax (e.g. [[link text]]((url))) and/or add some kind of escaping to allow for sending actual raw markup text? (see bef95d7/#1323)

allow entering of text links (messageEntityTextUrl) using markdown syntax
e.g.:
	[webogram source](https://github.com/zhukov/webogram/)
var markdownTestRegExp = /[`_*@]/
var markdownRegExp = /(^|\s|\n)(````?)([\s\S]+?)(````?)([\s\n\.,:?!;]|$)|(^|\s)(`|\*\*|__)([^\n]+?)\7([\s\.,:?!;]|$)|@(\d+)\s*\((.+?)\)/m
var markdownTestRegExp = /[`_*@]|\]\(/
var markdownRegExp = new RegExp('(^|\\s|\\n)(````?)([\\s\\S]+?)(````?)([\\s\\n\\.,:?!;]|$)|(^|\\s)(`|\\*\\*|__)([^\\n]+?)\\7([\\s\\.,:?!;]|$)|@(\\d+)\\s*\\((.+?)\\)|\\[([^\\]]+)\\]\\((' + urlRegExp + ')\\)', 'm')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it may be a bit hard to see what's going on here, let's go through it:
basically this just adds the regex part for matching text links at the very end - pseudo regex: /\[([^\]]+)\]\((urlRegExp)\)/.

To be able to insert and reuse urlRegExp from above the literal regex had to be converted to a string - to be concatenated with urlRegExp - that is then passed to the RegExp constructor, i.e. the delimiting /s were removed/replaced by single quotes and all back slashes had to be escaped (\ -> \\).

This adds two more (relevant) capturing groups:

  • match[12]: the link text
  • match[13]: the url
@stek29 stek29 requested a review from zhukov October 14, 2018 15:21
@T1MOXA
Copy link

T1MOXA commented Feb 18, 2020

It is a pity that nothing has changed in 2 years, and webogram still does not support markdown links (

@Aokromes Aokromes added the Fix label Feb 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 participants