').get(0),this.innerView=null,this.tooltip||(this.tooltip=jQuery("").addClass("footnote-tooltip").appendTo(".dokuwiki").get(0))}},{key:"selectNode",value:function(){this.dom.classList.add("ProseMirror-selectednode"),this.innerView||this.open()}},{key:"deselectNode",value:function(){this.dom.classList.remove("ProseMirror-selectednode"),this.innerView&&(this.dispatchOuter(),this.close())}},{key:"open",value:function(){var e=this;jQuery(this.tooltip).dialog({minWidth:1100,minHeight:550,title:LANG.plugins.prosemirror.footnoteViewTitle,modal:!0,appendTo:".dokuwiki",close:this.dispatchOuter.bind(this)});var t=new a.Schema((0,f.default)()),n=new c.default(t);this.innerView=new i.EditorView(this.tooltip,{state:o.EditorState.create({doc:a.Node.fromJSON(t,JSON.parse(this.node.attrs.contentJSON)),footnoteSchema:t,plugins:[n.getMenuPlugin(),(0,s.default)(t)]}),dispatchTransaction:this.dispatchInner.bind(this),handleDOMEvents:{mousedown:function(){e.outerView.hasFocus()&&e.innerView.focus()}},nodeViews:(0,u.default)()})}},{key:"close",value:function(){this.innerView&&(this.innerView.destroy(),this.innerView=null,this.tooltip.innerHTML="")}},{key:"dispatchInner",value:function(e){var t=this.innerView.state.applyTransaction(e).state;this.innerView.updateState(t)}},{key:"dispatchOuter",value:function(){var e={contentJSON:JSON.stringify(this.innerView.state.doc.toJSON())};if(e.contentJSON.length!==this.node.attrs.contentJSON.length){var t=this.getPos();this.outerView.dispatch(this.outerView.state.tr.setNodeMarkup(t,null,e))}}},{key:"update",value:function(e){if(!e.sameMarkup(this.node))return!1;if(this.node=e,this.innerView){var t=this.innerView.state,n=e.content.findDiffStart(t.doc.content);if(null!=n){var r=e.content.findDiffEnd(t.doc.content),o=r.a,i=r.b,a=n-Math.min(o,i);a>0&&(o+=a,i+=a),this.innerView.dispatch(t.tr.replace(n,i,e.slice(n,o)).setMeta("fromOutside",!0))}}return!0}},{key:"destroy",value:function(){this.innerView&&this.close()}},{key:"stopEvent",value:function(e){return this.innerView&&this.innerView.dom.contains(e.target)}},{key:"ignoreMutation",value:function(){return!0}}]),t}();t.default=d}]);
\ No newline at end of file
diff --git a/parser/CodeBlockNode.php b/parser/CodeBlockNode.php
index e03d2760..af73e68e 100644
--- a/parser/CodeBlockNode.php
+++ b/parser/CodeBlockNode.php
@@ -16,15 +16,77 @@ public function __construct($data, Node $parent)
public function toSyntax()
{
+// 555
+ $TAG = $this->data['attrs'];
$openingTag = 'data['attrs']['data-language'])) {
- $openingTag .= ' ' . $this->data['attrs']['data-language'];
+ if (!empty($TAG['data-language'])) {
+ $openingTag .= ' ' . $TAG['data-language'];
} else {
$openingTag .= ' -';
}
- if (!empty($this->data['attrs']['data-filename'])) {
- $openingTag .= ' ' . $this->data['attrs']['data-filename'];
+ if (!empty($TAG['data-filename'])) {
+ $openingTag .= ' ' . $TAG['data-filename'];
}
+ $extraTag = '';
+ if (isset($TAG['data-sln-old']))
+ {
+ $sln_old = $TAG['data-sln-old'];
+ if (is_numeric($sln_old))
+ {
+ $sln_old = (int) $sln_old;
+ }
+ else
+ {
+ $sln_old = 1;
+ }
+ }
+ if (isset($TAG['data-sln']))
+ {
+ $start_line_numbers_at = $TAG['data-sln'];
+ if (is_numeric($start_line_numbers_at))
+ {
+ $start_line_numbers_at = (int) $start_line_numbers_at;
+ if (!$extraTag) $extraTag = '[';
+ if ($start_line_numbers_at > 0)
+ $extraTag .= 'enable_line_numbers="true", ';
+ else
+ $extraTag .= 'enable_line_numbers="false", ';
+ $extraTag .= 'start_line_numbers_at="' . abs($start_line_numbers_at) .'"';
+ }
+ else
+ {
+ $extraTag = '[enable_line_numbers="false"';
+ }
+ }
+ if (isset($TAG['data-hle']))
+ {
+ $highlight_lines_extra = $TAG['data-hle'];
+ $arr = explode(',', $highlight_lines_extra);
+ $str = '';
+ foreach($arr as $val)
+ {
+ if ($str) $str .= ',';
+ if (is_numeric($val))
+ {
+ $ival = (int) $val;
+ if ($sln_old > 0 && $ival > 0)
+ $str .= $ival - $sln_old + 1;
+ else
+ $str .= abs($ival);
+ }
+ }
+ if ($str)
+ {
+ if (!$extraTag)
+ $extraTag = '[';
+ else
+ $extraTag .= ', ';
+ $extraTag .= 'highlight_lines_extra="' . $str . '"]';
+ }
+ elseif ($extraTag) $extraTag .= ']';
+ }
+ if ($extraTag) $openingTag .= ' ' . $extraTag;
+// 555---
$openingTag .= '>';
return $openingTag . "\n" . $this->data['content'][0]['text'] . "\n";
}
diff --git a/renderer.php b/renderer.php
index da6cbfc3..b164fad4 100644
--- a/renderer.php
+++ b/renderer.php
@@ -334,19 +334,48 @@ public function preformatted($text)
$this->cdata($text);
$this->nodestack->drop('preformatted');
}
-
- public function code($text, $lang = null, $file = null)
+// 555
+ public function code($text, $lang = null, $file = null, $ext = null)
{
$this->clearBlock();
$node = new Node('code_block');
$node->attr('class', 'code ' . $lang);
$node->attr('data-language', $lang);
- $node->attr('data-filename', $file);
+ $node->attr('data-filename', rtrim($file));
+ if ($ext)
+ {
+ if (isset($ext['start_line_numbers_at']))
+ {
+ $start_line_numbers_at = $ext['start_line_numbers_at'];
+ if (isset($ext['enable_line_numbers']) && ($ext['enable_line_numbers'] === false))
+ {
+ $start_line_numbers_at = -$start_line_numbers_at;
+ }
+ $node->attr('data-sln', $start_line_numbers_at);
+ $node->attr('data-sln-old', $start_line_numbers_at);
+ }
+ else
+ {
+ $node->attr('data-sln-old', '1');
+ }
+ if (isset($ext['highlight_lines_extra']))
+ {
+ $str = '';
+ asort($ext['highlight_lines_extra']);
+ foreach($ext['highlight_lines_extra'] as $hle)
+ {
+ if ($str) $str .= ',';
+ if ($start_line_numbers_at > 0) $hle += $start_line_numbers_at - 1;
+ $str .= $hle;
+ }
+ $node->attr('data-hle', $str);
+ }
+ }
$this->nodestack->addTop($node);
$this->cdata(trim($text, "\n"));
$this->nodestack->drop('code_block');
}
-
+// 555---
public function file($text, $lang = null, $file = null)
{
$this->code($text, $lang, $file);
diff --git a/script/nodeviews/CodeView.js b/script/nodeviews/CodeView.js
index e6aadb02..01639324 100644
--- a/script/nodeviews/CodeView.js
+++ b/script/nodeviews/CodeView.js
@@ -22,7 +22,20 @@ class CodeView extends AbstractNodeView {
.on('keydown', this.constructor.preventSubmit)
.on('blur', this.dispatchMetaUpdate.bind(this))
.attr('list', 'codelanguages');
+ this.$sln = jQuery('')
+ .prop('placeholder', 'start line num at')
+ .prop('size', '12')
+ .on('keydown', this.constructor.preventSubmit)
+ .on('blur', this.dispatchMetaUpdate.bind(this));
+ this.$slno = jQuery('')
+ .prop('type', 'hidden');
+ this.$hle = jQuery('')
+ .prop('placeholder', 'highlight lines extra')
+ .prop('size', '40')
+ .on('keydown', this.constructor.preventSubmit)
+ .on('blur', this.dispatchMetaUpdate.bind(this));
this.$title.append(this.$fn).append(this.$lang);
+ this.$title.append(this.$sln).append(this.$slno).append(this.$hle);
this.$fileDom.append(this.$title);
this.$contentWrapper = jQuery('
');
this.$fileDom.append(this.$contentWrapper);
@@ -34,6 +47,9 @@ class CodeView extends AbstractNodeView {
this.$fn.val(attrs['data-filename']);
this.$lang.val(attrs['data-language']);
+ this.$sln.val(attrs['data-sln']);
+ this.$slno.val(attrs['data-sln-old']);
+ this.$hle.val(attrs['data-hle']);
Object.entries(attrs).forEach(([key, value]) => this.dom.setAttribute(key, value));
}
@@ -48,6 +64,9 @@ class CodeView extends AbstractNodeView {
const newAttrs = {
'data-filename': this.$fn.val(),
'data-language': this.$lang.val(),
+ 'data-sln': this.$sln.val(),
+ 'data-sln-old': this.$slno.val(),
+ 'data-hle': this.$hle.val(),
};
const nodeStartPos = this.getPos();
this.outerView.dispatch(this.outerView.state.tr.setNodeMarkup(
diff --git a/script/schema.js b/script/schema.js
index 60947f44..408c36f4 100644
--- a/script/schema.js
+++ b/script/schema.js
@@ -78,6 +78,9 @@ export default function getSpec() {
class: { default: 'code' },
'data-filename': { default: '' },
'data-language': { default: '' },
+ 'data-sln': { default: '' },
+ 'data-sln-old': { default: '' },
+ 'data-hle': { default: '' },
};
codeBlock.toDOM = function toDOM(node) {
return ['pre', node.attrs, 0];