Forgot password?
 Create new account
View 196|Reply 11

新论坛继续支持 TikZ

[Copy link]

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

kuing Posted at 2022-5-22 23:19:43 |Read mode
这里有个正弦函数图:

如果看不到,或许需要对浏览器清理缓存再刷新。
代码如下
  1. [tikz]
  2. \begin{tikzpicture}
  3. \draw plot[domain=-3.14:3.14](\x,sin(\x r));
  4. \draw[->] (-3.3,0)--(3.3,0);
  5. \draw[->] (0,-1)--(0,1);
  6. \end{tikzpicture}
  7. [/tikz]
Copy the Code

用法和旧论坛是一样的。

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-5-22 23:33:27
这次新论坛的实现方法与旧论坛稍有不同。
旧论坛是直接用 js 对帖子内容搜索替换,还需要对 code 另外处理。
而新论坛由于 BBcode 已经不存在中括号问题,所以这次是
直接设 BBcode [tikz] 的替换是 <tikz>{1}</tikz> 再用 js 处理它,
就不会影响 code ,效率应该也会高些。(虽然未必体现得出来)

不过依然存在像 \draw[color=... 这种的 bug……

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-5-22 23:37:42
kuing 发表于 2022-5-22 16:33
这次新论坛的实现方法与旧论坛稍有不同。
旧论坛是直接用 js 对帖子内容搜索替换,还需要对 code 另外处理 ...
直接改php代码吧,不需要用<tikz>标签,这样的话,页面上直接就是img标签,就可以被搜索引擎爬虫收入索引

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-5-22 23:40:49
hbghlyj 发表于 2022-5-22 23:37
这样的话,页面上直接就是img标签,就可以被搜索引擎爬虫收入索引
没有吧?

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-5-22 23:43:24
哦哦对对对...忘记考虑了...Dz好像还是有一个lazyload...所以img标签的src最初不是它的src...所以还是不能被搜索引擎索引到

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-5-22 23:50:12
hbghlyj 发表于 2022-5-22 23:43
哦哦对对对...忘记考虑了...Dz好像还是有一个lazyload...所以img标签的src最初不是它的src...所以还是不 ...
其实我想说的不是这点,我现在的方法,页面上应该是 <tikz>tikz代码</tikz> 吧?变成图片是之后由 js 处理的

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-5-22 23:51:40
kuing 发表于 2022-5-22 16:50
其实我想说的不是这点,我现在的方法,页面上应该是 tikz代码 吧?变成图片是之后由 js 处理的 ...
直接改php代码吧(discuzcode),不需要用<tikz>标签,这样的话,页面上直接就是img标签

701

Threads

110K

Posts

910K

Credits

Credits
94177
QQ

Show all posts

 Author| kuing Posted at 2022-5-22 23:52:52
hbghlyj 发表于 2022-5-22 23:51
直接改php代码吧(discuzcode),不需要用标签,这样的话,页面上直接就是img标签  ...
我不会改啊
Q上问你你又不理我

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-5-23 02:55:58
Last edited by hbghlyj at 2022-7-17 19:56:00
kuing 发表于 2022-5-22 16:33
这次新论坛的实现方法与旧论坛稍有不同。
旧论坛是直接用 js 对帖子内容搜索替换,还需要对 code 另外处理 ...
直接去修改php代码(discuzcode函数)就不存在这种bug了.
它里面是一些正则表达式替换(preg_replace),如果我们先替换tikz标签,再替换color,就不存在这个问题了
这是因为,经过tikz标签替换后,[$ $color=red]变成%5Bcolor%3Dred%5D,就不会被[$ $color]匹配到了.

另外,我发现一个事情:像[quote],[code]这种如果只有左标签,没有右标签,是不会替换的;但是[$ $color=red]如果只有左标签,同样会被替换

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-7-18 02:57:02
hbghlyj 发表于 2022-5-22 19:55
直接去修改php代码(discuzcode函数)就不存在这种bug了.
它里面是一些正则表达式替换(preg_replace),如果 ...
顶一下

15

Threads

948

Posts

110K

Credits

Credits
12412

Show all posts

色k Posted at 2022-7-18 03:15:13 From the mobile phone
hbghlyj 发表于 2022-7-18 02:57
顶一下
顶也没用,在可预见的将来我都不会有耐心去改什么php。
目前这tikz大概能用就行了,反正也没几个人用。
这名字我喜欢

3147

Threads

8493

Posts

610K

Credits

Credits
66163
QQ

Show all posts

hbghlyj Posted at 2022-7-19 18:17:52
function_discuzcode.php里面有两种替换标签的方式:
第一种是139~172行
  1.                 $message = str_replace(array(
  2.                         '[/color]', '[/backcolor]', '[/size]', '[/font]', '[/align]', '[b]', '[/b]', '[s]', '[/s]', '[hr]', '[/p]',
  3.                         '[i=s]', '[i]', '[/i]', '[u]', '[/u]', '[list]', '[list=1]', '[list=a]',
  4.                         '[list=A]', "\r\n[*]", '[*]', '[/list]', '[indent]', '[/indent]', '[/float]'
  5.                         ), array(
  6.                         '</font>', '</font>', '</font>', '</font>', '</div>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="l" />', '</p>', '<i class="pstatus">', '<i>',
  7.                         '</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
  8.                         '<ul type="A" class="litype_3">', '<li>', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
  9.                         ), preg_replace(array(
  10.                         "/\[color=([#\w]+?)\]/i",
  11.                         "/\[color=((rgb|rgba)\([\d\s,]+?\))\]/i",
  12.                         "/\[backcolor=([#\w]+?)\]/i",
  13.                         "/\[backcolor=((rgb|rgba)\([\d\s,]+?\))\]/i",
  14.                         "/\[size=(\d{1,2}?)\]/i",
  15.                         "/\[size=(\d{1,2}(\.\d{1,2}+)?(px|pt)+?)\]/i",
  16.                         "/\[font=([^\[\<]+?)\]/i",
  17.                         "/\[align=(left|center|right)\]/i",
  18.                         "/\[p=(\d{1,2}|null), (\d{1,2}|null), (left|center|right)\]/i",
  19.                         "/\[float=left\]/i",
  20.                         "/\[float=right\]/i"
  21.                         ), array(
  22.                         "<font color=\"\\1\">",
  23.                         "<font style=\"color:\\1\">",
  24.                         "<font style=\"background-color:\\1\">",
  25.                         "<font style=\"background-color:\\1\">",
  26.                         "<font size=\"\\1\">",
  27.                         "<font style=\"font-size:\\1\">",
  28.                         "<font face=\"\\1\">",
  29.                         "<div align=\"\\1\">",
  30.                         "<p style=\"line-height:\\1px;text-indent:\\2em;text-align:\\3\">",
  31.                         "<span style=\"float:left;margin-right:5px\">",
  32.                         "<span style=\"float:right;margin-left:5px\">"
  33.                         ), $message));
Copy the Code

第二种是181~186行:
  1.                         if(strpos($msglower, '[/quote]') !== FALSE) {
  2.                                 $message = preg_replace("/\s?\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s?/is", tpl_quote(), $message);
  3.                         }
  4.                         if(strpos($msglower, '[/free]') !== FALSE) {
  5.                                 $message = preg_replace("/\s*\[free\][\n\r]*(.+?)[\n\r]*\[\/free\]\s*/is", tpl_free(), $message);
  6.                         }
Copy the Code

容易看出,第一种是分别替换开标签与闭标签, 而第二种是将开标签与闭标签配对再替换.
第一种的效果是
  1. ...text 1...[color=red]...text 2...
Copy the Code

会被替换为
  1. ...text 1...<font color="red">...text 2...
Copy the Code

不论text 2中是否包含[​/color].
而第二种的效果是
  1. ...text 1...[quote]...text 2...
Copy the Code

只有当text2中包含[​/quote]时,才会被替换.

手机版Mobile version|Leisure Math Forum

2025-4-20 22:25 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list