markdown 自定义一个锚点
2024-10-17 22:23:38
//自定义锚点 s
"m[": function mlink( text ) {
var orig = String(text);
// Inline content is possible inside `link text`
var res = inline_until_char.call( this, text.substr(2), "]" ); // No closing ']' found. Just consume the [
if ( !res )
return [ 1, "m" ]; var consumed = 2 + res[ 0 ],
children = res[ 1 ],
link,
attrs; // At this point the first [...] has been parsed. See what follows to find
// out which kind of link we are (reference or direct url)
text = text.substr( consumed ); // [link text](/path/to/img.jpg "Optional title")
// 1 2 3 <--- captures
// This will capture up to the last paren in the block. We then pull
// back based on if there a matching ones in the url
// ([here](/url/(test))
// The parens have to be balanced
var m = text.match( /^\s*\([ \t]*([^"']*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ );
//alert(text+"-"+ m)
if ( m ) { var url = m[1];
consumed += m[0].length; if ( url && url[0] === "<" && url[url.length-1] === ">" )
url = url.substring( 1, url.length - 1 ); // If there is a title we don't have to worry about parens in the url
if ( !m[3] ) {
var open_parens = 1; // One open that isn't in the capture
for ( var len = 0; len < url.length; len++ ) {
switch ( url[len] ) {
case "(":
open_parens++;
break;
case ")":
if ( --open_parens === 0) {
consumed -= url.length - len;
url = url.substring(0, len);
}
break;
}
}
} // Process escapes only
url = this.dialect.inline.__call__.call( this, url, /\\/ )[0]; attrs = { };
if ( m[1] !== undefined)
attrs.id = m[1]; link = [ "link", attrs ].concat( children );
return [ consumed, link ];
} // [Alt text][id]
// [Alt text] [id]
m = text.match( /^\s*\[(.*?)\]/ ); if ( m ) { consumed += m[ 0 ].length; // [links][] uses links as its reference
attrs = { ref: ( m[ 1 ] || String(children) ).toLowerCase(), original: orig.substr( 0, consumed ) }; link = [ "link_ref", attrs ].concat( children ); // We can't check if the reference is known here as it likely wont be
// found till after. Check it in md tree->hmtl tree conversion.
// Store the original so that conversion can revert if the ref isn't found.
return [ consumed, link ];
} // [id]
// Only if id is plain (no formatting.)
if ( children.length === 1 && typeof children[0] === "string" ) { attrs = { ref: children[0].toLowerCase(), original: orig.substr( 0, consumed ) };
link = [ "link_ref", attrs, children[0] ];
return [ consumed, link ];
} // Just consume the "["
return [ 1, "[" ];
},
//自定义锚点 e
调用 :
自定义一个id为aaa的锚点
m[](aaa) 空格空格
空格空格
next
最新文章
- 窥探Swift系列博客说明及其Swift版本间更新
- Linux json解析jq
- FAILURE: Build failed with an exception.
- 如何去设计一个自适应的网页设计或HTMl5
- javascript线程解释(setTimeout,setInterval你不知道的事)---转载
- 目录重定向的源代码工程( linux平台利用VFS实现目录重定向驱动)虚拟磁盘MINIPORT驱动代码(雨中风华)
- Java学习----构造方法的重载
- 写两个线程,一个对n每次加一,一个对n每次减一
- 【科研论文】基于文件解析的飞行器模拟系统软件设计(应用W5300)
- kernel hexdump分析 (2.0)
- ubuntu16.10下安装erlang和RabbitMQ
- WEB前端开发记录PS常见操作
- 前端 - Ajax (1)
- reveal破解
- Selenium基础知识(三)元素判断
- DAG最小路径点覆盖
- IOS的动态性
- troubleshooting-Kerberos 鉴权异常
- XtraForm
- mysqladmin: connect to server at &#39;localhost&#39; failed
热门文章
- 基于Redis的CustomerSessionProvider(二)
- ASP.NET MVC 用户登录Login
- WampServer Mysql配置
- Exchange 2016 创建日程,远程服务器返回错误: (401) 未经授权
- 彻底抛弃PeopleEditor,SharePoint中利用Jquery Chosen创建新的人员选择器
- SQLAlchemy on the way
- 关闭Windows 2008下面应用程序出错后的提示
- 通过Jasmine和Guard自动测试JavaScript
- 应用程序启动后修改自身EXE文件或自删除EXE文件(附VC++6.0源码)
- 利用GeneratedKeyHolder获得新增数据主键值