Skip to content

Commit

Permalink
Tune MD class
Browse files Browse the repository at this point in the history
  • Loading branch information
energy-coresky committed Feb 18, 2025
1 parent a115a22 commit 1dfffc6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion w2/_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ oc: {'{': '}', '(': ')', '[': ']'} # ->oc to mean Open/Close chars

color: # r g z y m j in sky.css
#.schemes
w_base: {r:#f77, g:#00e, d:#000, c:#2b3, m:#93c, j:#000} # c-comment d-default j:#c41
w_base: {r:#f77, g:#00e, d:#000, c:#2b3, m:#93c, j:#b88} # c-comment d-default j:#c41
v_php: {r:#d00, g:#070, d:#00b, c:#ff8000, m:#000, j:#c41} # native php highlight_string(..) function colors
z_php: {r:#d00, g:#070, d:#00b, c:#ff8000, m:#000, j:#c41}
b_far: {r:#ff5, g:#fff, d:#7ee, c:#b84, m:#888, j:#68a} # #c41
Expand Down
44 changes: 29 additions & 15 deletions w2/md.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,24 @@ protected function parse(): ?stdClass {
} while ($this->line($x));
$this->j = 0;
$this->last->attr['last'] = 1;

foreach ($this->for as $rf => $set) {
if (!isset($this->ref[$rf]))
continue;
$url = $this->ref[$rf];
foreach ($set as $node) {
$head = substr($node->attr['head'], 1, -1);
if ('!' == $node->val[0]) { # img
$node->name = 'img';
$node->attr = ['src' => $url, 'alt' => $head, 't' => $node->val, 'c' => 'c'];
$node->val = 0;
} else {
$node->name = 'a';
$node->attr = ['href' => $url, 't' => $node->val, 'c' => 'g'];
$node->val = $head;
}
}
}
return $this->root->val;
}

Expand Down Expand Up @@ -338,8 +356,12 @@ private function line($x) {
$b = isset($in[$j - 1]) && !strpbrk($in[$j - 1], " \t\r\n") ? 1 : 0; # end or not
$j += strlen($uu = substr($in, $j, strspn($in, $y, $j)));
$b += isset($in[$j]) && !strpbrk($in[$j], " \t\r\n") ? 2 : 0; # start or not
$this->push('-i', $uu, ['b' => $b]);
$this->up->attr['in'] = $uu;
if (3 != $b || '*' == $y || '`' == $y) {
$this->push('-i', $uu, ['b' => $b]);
$this->up->attr['in'] = $uu;
} else {
$this->push('#text', $uu);
}
} else {
$this->add($y);
}
Expand Down Expand Up @@ -384,21 +406,21 @@ private function square($x, $y, $inline = false, $img = false) { # 2do footnote
goto schem_1;
if ('[' == $chr) {
$rf = strtolower($tail);
goto schem_2; # scheme: [][q] or [a][q]
goto schem_2;
}
} elseif (':' == $chr) {
if ($inline || ':' == trim($tail = $this->cspn("\n", $j)))
return false; # not reference
$this->use_close($x);
$this->ref[$rf] = trim(substr($tail, 1));
return $this->add($head . $tail, ['c' => 'm']);
return $this->add($head . $tail, ['c' => 'j']);
} else {
schem_1: # scheme: [q]
if (2 == $len)
return false;
schem_2:
$this->for[$rf][] = true;
$p =& $this->for[$rf][array_key_last($this->for[$rf])];
$this->j += strlen($t = ($img ? '!' : '') . $head . $tail);
return $this->for[$rf][] = $this->push('#a', $t, ['head' => $head]);
}
$this->j += strlen($t = ($img ? '!' : '') . $head . $tail);
if ($img)
Expand Down Expand Up @@ -589,14 +611,6 @@ private function cspn($set, $j = 0, &$sz = null) { # collect other than $set
return substr($this->in, $j ?: $this->j, $sz = strcspn($this->in, $set, $j ?: $this->j));
}
}
/* foreach ($this->for as $i => $for) {
if (isset($this->ref[$for])) {
#$this->tok[$i][4] = $this->ref[$for];
} else {
#$this->tok[$i][2] = $this->tok[$i][1];
#$this->tok[$i][0] = 11;
}
}
/*
sprintf('<img src="%s" alt="%s">', $p4, substr($p3, 1, -1)) # image
trace($x->close, '===');*/

0 comments on commit 1dfffc6

Please sign in to comment.