编辑“︁Module:Chem”︁

警告:您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您登录创建账号,您的编辑会以您的用户名署名,此外还有其他益处。

该编辑可以被撤销。 请检查下面的对比以核实您想要撤销的内容,然后发布下面的更改以完成撤销。

最后版本 您的文本
第1行: 第1行:
local p={}


function p.chem(frame)
  local args=frame:getParent().args
  --local args=frame
  local chemstr=""
  for i, v in pairs(args) do
    if type(i)=="number" then
      chemstr=chemstr .. v
    else
      chemstr=chemstr .. i .. "=" .. v
    end
  end
  chemstr=mw.ustring.gsub(chemstr, "%s", "")
  local res={}
  local len=mw.ustring.len(chemstr)
  local i=1
  local norm=true
  local sup=false
  while i<=len do
    local ch=mw.ustring.sub(chemstr, i, i)
    if ch=="." or ch=="·" then
      table.insert(res, "·")
      norm=true
    elseif ch=="=" then
      table.insert(res, "=")
      norm=true
    elseif ch=="^" then
      sup=true
      norm=false
    elseif ch=="_" then
      sup=false
      norm=false
    elseif ch=="+" or ch=="-" then
      if i~=len then
        local nc=mw.ustring.sub(chemstr, i+1, i+1)
        norm=true
        if nc=="+" or nc=="-" then
          norm=false
        end
      end
      if not norm then
        table.insert(res, "<sup>" .. ch .. "</sup>")
      else
        table.insert(res, ch)
      end
      norm=true
    elseif mw.ustring.match(ch, "%d") then
      if not norm then
        if sup then
          table.insert(res, "<sup>" .. ch .. "</sup>")
        else
          table.insert(res, "<sub>" .. ch .. "</sub>")
        end
      else
        table.insert(res, ch)
      end
    else
      table.insert(res, ch)
      norm=false
      sup=false
    end
    i=i+1
  end
  return mw.html.create("span"):wikitext(table.concat(res))
end
return p
请注意,所有对锑星百科的贡献均被视为依照Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)发表(详情请见锑星百科:著作权)。如果您不希望您的文字作品被随意编辑和分发传播,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源。未经许可,请勿提交受著作权保护的作品!
取消 编辑帮助​(在新窗口中打开)
以下为几个常用的符号,点选你想要的符号后,它会立即出现在编辑框中你所指定的位置。

检视此模板

该页面使用的模板: