私はWYSIHTML5( https://github.com/xing/wysihtml5)に基づいたWYSIHTML5 Bootstrap( http://jhollingworth.github.com/bootstrap-wysihtml5 )を使用しています。ウェブサイト。
コードをエディターで処理してから、HighlightJSで構文を強調表示できるようにしたいと思います。
新しいボタンを作成し、wysihtml5.jsで使用されているメソッドを複製して、代わりに次<b>
を使用して太字のオンとオフを切り替えました。<pre>
(function(wysihtml5) {
var undef;
wysihtml5.commands.pre = {
exec: function(composer, command) {
return wysihtml5.commands.formatInline.exec(composer, command, "pre");
},
state: function(composer, command, color) {
return wysihtml5.commands.formatInline.state(composer, command, "pre");
},
value: function() {
return undef;
}
};
})(wysihtml5)
しかし、それだけでは十分ではありません。エディターは、編集時にタグを非表示にします。<pre>
コンテンツをとの両方でラップできる必要があります<code>
。<pre><code></code></pre>
。
これは、wysihtml5で使用されているものとは異なる関数を作成することを意味しますが、方法がわかりません...誰かがそれを手伝ってくれませんか?
wysihtml5のformatInline関数のコードは次のとおりです。
wysihtml5.commands.formatInline = {
exec: function(composer, command, tagName, className, classRegExp) {
var range = composer.selection.getRange();
if (!range) {
return false;
}
_getApplier(tagName, className, classRegExp).toggleRange(range);
composer.selection.setSelection(range);
},
state: function(composer, command, tagName, className, classRegExp) {
var doc = composer.doc,
aliasTagName = ALIAS_MAPPING[tagName] || tagName,
range;
// Check whether the document contains a node with the desired tagName
if (!wysihtml5.dom.hasElementWithTagName(doc, tagName) &&
!wysihtml5.dom.hasElementWithTagName(doc, aliasTagName)) {
return false;
}
// Check whether the document contains a node with the desired className
if (className && !wysihtml5.dom.hasElementWithClassName(doc, className)) {
return false;
}
range = composer.selection.getRange();
if (!range) {
return false;
}
return _getApplier(tagName, className, classRegExp).isAppliedToRange(range);
},
value: function() {
return undef;
}
};
})(wysihtml5);