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

Module:WikitextLC

猛汉♂百科,万男皆可猛的百科全书!转载请标注来源页面的网页链接,并声明引自猛汉百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

本模块用于以Lua语言执行字词转换。

在模块中调用本模块时可以输入以下代码:

local WikitextLC = require( 'Module:WikitextLC' )

用法可参见Module:NoteTA

  1. local p = {}
  2. --- Construct an inline conversion from a table input.
  3. -- @param content table of the form
  4. -- { ["zh-cn"]='foobar', ["zh-tw"]='firecat', ["zh-hk"]='' }
  5. -- @returns string
  6. -- "-{zh-cn:foobar;zh-tw:firecat;zh-hk:<span></span>}-"
  7. --
  8. -- @fixme allow for generating output without "-{" "}-", so that
  9. -- it can be used with the last three wrappers.
  10. function p.selective( content )
  11. local text = '-{'
  12. for variant, value in pairs( content ) do
  13. if value == '' then
  14. value = '<span></span>'
  15. end
  16. text = text .. variant .. ':' .. value .. ';'
  17. end
  18. text = text .. '}-'
  19. return text
  20. end
  21. --- Write some text with a limited set of variants to convert to
  22. --
  23. -- @param content text to be written
  24. -- @param variant a variant (string), or a list of variants
  25. -- (semicolon-deliminated string, or table of strings)
  26. -- @param[opt] force convert even under "zh" (no conversion) locale
  27. function p.converted( content, variant, force )
  28. if type( variant ) == 'table' then
  29. variant = table.concat( variant, ';' )
  30. end
  31. return '-{' .. ( force and '' or 'zh;' ) .. variant .. '|' .. content .. '}-'
  32. end
  33. --- Wraps some "raw text" to not convert.
  34. --
  35. -- @fixme Is the "R" flag some undocumented/undefined no-op magic?
  36. -- Are we using it instead of the old '-{' .. content .. '}-'
  37. -- to avoid confusion caused by a flag in the "content"?
  38. function p.raw( content )
  39. return '-{R|' .. content .. '}-'
  40. end
  41. --- Wraps a title conversion rule.
  42. function p.title( content )
  43. return '-{T|' .. content .. '}-'
  44. end
  45. --- Wraps a (hidden) conversion rule definition.
  46. function p.hidden( content )
  47. return '-{H|' .. content .. '}-'
  48. end
  49. return p