置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Sandbox/Ave/Moe

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [创建] [刷新]
  1. -- 初始化模块
  2. local getArgs = require('Module:Arguments').getArgs
  3. local moe = {}
  4. local moePoint = {}
  5. -- 对分割符进行处理
  6. function split(str, splitter)
  7. local splitCount = getSplitCount(str, splitter)
  8. if splitCount == 1 then
  9. local head = str:gsub("(" .. splitter .. ").*", "")
  10. local category = "[[Category:" .. head .. "]]"
  11. local start, finish = string.find(str, "%" .. splitter)
  12. if start then
  13. local tail = string.sub(str, start + 1)
  14. if splitter == "&" then
  15. if tail == "斜体" or tail == "i" or tail == "em" then
  16. return "<i>[[" .. head .. "]]</i>" .. category
  17. elseif tail == "粗体" or tail == "b" then
  18. return "<b>[[" .. head .. "]]</b>" .. category
  19. elseif tail == "删除" or tail == "删除线" or tail == "划掉" or tail == "s" or tail == "del" then
  20. return "<s>[[" .. head .. "]]</s>" .. category
  21. elseif tail == "双线" or tail == "双横线" or tail == "双删除线" then
  22. return '<div style="text-decoration:line-through;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
  23. elseif tail == "下划线" or tail == "u" then
  24. return "<u>[[" .. head .. "]]</u>" .. category
  25. elseif tail == "双下划线" then
  26. return '<div style="text-decoration:underline;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
  27. elseif tail == "虚线" then
  28. return '<span style="border-bottom:dashed 0.05em;display:inline-block;">[[' ..head .. "]]</span>" .. category -- 存在异常,出现了错误换行
  29. elseif tail == "波浪" or tail == "波浪线" or tail == "wave" then
  30. return '<div style="text-decoration:wavy underline;display:inline-block;">[[' ..head .. "]]</div>" .. category
  31. elseif tail == "黑幕" then
  32. return "{{黑幕|[[" .. head .. "]]}}" .. category
  33. elseif tail == "模糊" or tail == "黑雾" or tail == "毛玻璃" or tail == "glass" then
  34. return "{{文字模糊|[[" .. head .. "]]|哼,果然还是好奇呢|time=70}}" .. category
  35. else
  36. return "[[" .. head .. "|" .. tail .. "]]" .. category
  37. end
  38. elseif splitter == "$" then
  39. if tail == "斜体" or tail == "i" or tail == "em" then
  40. return "<i>[[" .. head .. "]]</i>" .. category
  41. elseif tail == "粗体" or tail == "b" then
  42. return "<b>[[" .. head .. "]]</b>" .. category
  43. elseif tail == "删除" or tail == "删除线" or tail == "划掉" or tail == "s" or tail == "del" then
  44. return "<s>[[" .. head .. "]]</s>" .. category
  45. elseif tail == "双线" or tail == "双横线" or tail == "双删除线" then
  46. return '<div style="text-decoration:line-through;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
  47. elseif tail == "下划线" or tail == "u" then
  48. return "<u>[[" .. head .. "]]</u>" .. category
  49. elseif tail == "双下划线" then
  50. return '<div style="text-decoration:underline;text-decoration-style:double;display:inline-block;">' .. head .. "</div>" .. category
  51. elseif tail == "虚线" then
  52. return '<span style="border-bottom:dashed 0.05em;display:inline-block;">[[' ..head .. "]]</span>" .. category -- 存在异常,出现了错误换行
  53. elseif tail == "波浪" or tail == "波浪线" or tail == "wave" then
  54. return '<div style="text-decoration:wavy underline;display:inline-block;">[[' ..head .. "]]</div>" .. category
  55. elseif tail == "黑幕" then
  56. return "{{黑幕|[[" .. head .. "]]}}" .. category
  57. elseif tail == "模糊" or tail == "黑雾" or tail == "毛玻璃" or tail == "glass" then
  58. return "{{文字模糊|[[" .. head .. "]]|哼,果然还是好奇呢|time=70}}" .. category
  59. else
  60. return "[[" .. tail .. "]]" .. category
  61. end
  62. end
  63. end
  64. elseif splitCount == 2 then
  65. return "77977"
  66. end
  67. end
  68. function checkFirstSplit(str)
  69. local startA = string.find(str, "[,,]")
  70. local startB = string.find(str, "[·/]")
  71. if startA and startB then
  72. return startA < startB and "A" or "B"
  73. elseif not (startA or startB) then
  74. return "C"
  75. elseif not startA then
  76. return "B"
  77. else
  78. return "A"
  79. end
  80. end
  81. -- 预处理模块,将分隔符全部处理为方便后续判断的符号
  82. function pretreat(str, splitter)
  83. local specials = {",", ",", "·", "/"}
  84. local first = nil
  85. for _, special in ipairs(specials) do
  86. if string.find(str, special, 1, true) then
  87. first = special
  88. break
  89. end
  90. end
  91. for _, special in ipairs(specials) do
  92. str = string.gsub(str, special, splitter)
  93. end
  94. return str
  95. end
  96. -- 获取目标字符串中有几个分割符
  97. function getSplitCount(str, splitter)
  98. local count = 0
  99. for i = 1, #str do
  100. if string.sub(str, i, i) == splitter then
  101. count = count + 1
  102. end
  103. end
  104. return count
  105. end
  106. -- 获取表的长度
  107. function getTableLenth(tab)
  108. local count = 0
  109. for _ in pairs(tab) do
  110. count = count + 1
  111. end
  112. return count
  113. end
  114. -- 主函数,用于分析传入的参数中是否包含分隔符[,,]或[·/],将接收到的所有参数依次压入moe中
  115. function moe.analysis(point)
  116. local points = getArgs(point)
  117. for pos = 1, getTableLenth(points) do
  118. local str = points[pos]
  119. for i = 1, #str do
  120. if checkFirstSplit(str) == "A" then
  121. return split(pretreat(str, "&"), "&")
  122. --return table.insert(moePoint, split(pretreat(str, "&"), "&")) -- 使用","或","分割的场合
  123. elseif checkFirstSplit(str) == "B" then
  124. return split(pretreat(str, "$"), "$")
  125. --return table.insert(moePoint, split(pretreat(str, "$"), "$")) -- 使用"·"或"/"分割的场合
  126. else
  127. return table.insert(moePoint, str) -- 如果没有分隔符,则直接压入
  128. end
  129. end
  130. end
  131. return table.concat(moePoint, "、") -- 取出表内所有元素并合并为一个大字符串输出
  132. end
  133. return moe