奇技淫巧之浏览器秒秒钟变编辑器
此文是翻译来的,原文戳这里。
由来
有时,我仅仅想输入一些乱码。仅仅想放空自己。用编辑器来输入这些胡言乱语会使我很苦恼,因为这样会弄乱我项目的工作区。(我很挑剔,我懂得)
所以我就这么做。自从我生活在有浏览器的地方,我就只需打开新的标签,然后在地址栏里输入下面的内容:
data:text/html, <html contenteditable>
瞧,浏览器记事本。
为什么代码会有效
你不需要记住它。它不是rocket science(哈哈,这里不是火箭科学,更不是那部电影,此处指艰深的学问以及复杂伤身的工作)。我们正在使用数据URI格式Data URI’s format并且告诉浏览器对html进行渲染(尝试一下”javascript:alert(‘Bazinga’);”)。html所说的内容是一种带有HTML的contenteditable(内容可编辑)的属性的HTML line。这仅仅在能识别这种属性的现代的浏览器上是有效的。点击编辑吧!
以上就是翻译的全部内容,原文戳这里。
效果图:
More
在作者发布这个消息之后,有很多的大神开始开动脑筋,绞尽脑汁,开始创作了各种碉堡的浏览器编辑器。下面这一款我比较喜欢的:
1 data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" );</script>
效果出众,最重要的是支持多种语言想用其它的语言的话,仅仅需要把ace/mode/python用下面的换掉即可:
1 Markdown -> `ace/mode/markdown` 2 Python -> `ace/mode/ruby` 3 C/C++ -> `ace/mode/c_cpp` 4 Javscript -> `ace/mode/javascript` 5 Java -> `ace/mode/java` 6 Scala- -> `ace/mode/scala` 7 CoffeeScript -> `ace/mode/coffee` 8 and 9 css, html, php, latex, 10 tex, sh, sql, lua, clojure, dart, typescript, go, groovy, json, jsp, less, lisp, 11 lucene, perl, powershell, scss, textile, xml, yaml, xquery, liquid, diff and many more...
更碉堡的是,主题也可以换的,仅仅把ace/theme/monokai用下面的换掉即可:
1 Eclipse -> ace/theme/eclipse 2 GitHub -> ace/theme/github 3 TextMate -> ace/theme/textmate 4 and 5 ambiance, dawn, chaos, chrome, dreamweaver, xcode, vibrant_ink, solarized_dark, solarized_light, tomorrow, tomorrow_night, tomorrow_night_blue, 6 twilight, tomorrow_night_eighties, pastel_on_dark and many more..