我基本上是編寫自己的Markdown解析器。我想檢測一個字符串中的URL,並用錨標記包裝它,如果它是一個有效的URL。例如:在文本中查找URL並將其包裹在錨定標記中
string = 'here is a link: http://google.com'
# if string matches regex (which it does)
# should return:
'here is a link: <a href="http://google.com">http://google.com</a>'
# but this would remain unchanged:
string 'here is a link: google.com'
我該如何做到這一點?
如果您可以將我指向現有的可用作示例的Ruby markdown解析器中的代碼,則可獲得額外獎勵。
你想要什麼協議,允許? 'HTTP://'? '的https://'? 'FTP://'? 'IRC://'? '的telnet://'? – Phrogz
以下是他們如何在Kramdown中執行此操作: –
注意:您必須刪除鏈接上面,使其工作。 –