当前位置: 首页 > news >正文

手机网站 收录适合ps做图的素材网站

手机网站 收录,适合ps做图的素材网站,怎么做卖辅助网站,自己做的网站怎么发布视频教程cTinML转html 前言解析解释转译html类定义开头html 结果这是最终效果#xff08;部分#xff09;#xff1a; ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6cf6c3e3c821446a84ae542bcc2652d4.png) 前言 在python.tkinter设计标记语言(转译2-html)中提到了将Ti… cTinML转html 前言解析解释转译html类定义开头html 结果这是最终效果部分 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6cf6c3e3c821446a84ae542bcc2652d4.png) 前言 在python.tkinter设计标记语言(转译2-html)中提到了将TinML转为静态html的python实现方法在HtmlRender - c实现的html生成类中又提供了我自己写的基于c编辑html的简单方式这篇笔记就是使用c将tinml转为静态html。 本示例未使用任何第三方库除了我之前提供的HtmlRender类但是在html中代码高亮方面使用了在线的highlight.js。 整套流程下来和基于python的TinText平台类似都是先解析TinML标记文本段再给每个标记赋以特定含义解释过程最后通过这些解释后的内容生成html结构生成html文本。 项目示例CppTinParser: TinML to html by c 解析 这一部分是对TinML标记的语法解析。 class TinLexer{public:TinLexer(string contents){this-content \n contents \n;}void run_test();vectorstring run();vectormapstring,vectorstring lex();private:string content;};主要解析功能就是对每一行TinML标记文本段进行基于上下文标记的正则匹配和结构解析这部分相当于TinText项目中的TinParser 单行TinML标记分为标记名称和标记参数组多行模式TinML转为单行TinML标记解析后格式 部分代码如下 vectormapstring,vectorstring TinLexer::lex(){// 预处理// tackle tinfile: add context of the specific TinML file into this-content// 此部分代码省略可见程序源码// ...vectormapstring,vectorstring tinresults;//总结果vectorstring contents;string nowtag;//当前标签contents split(this-content, \n);bool Lines false;//多行模式regex pattern(^(.*?)(.*));smatch result;vectorstring args;//参数列表for (const auto i : contents){if (size(i) 1){// 实际上是empty不过貌似写不对// 既有可能是因为getline将\n转为\0导致该字符串截止continue;}if (size(i)2 i.substr(0,2)|-){// cout Comment: i endl;continue;}mapstring,vectorstring lineargs;//单行参数if (Lines){if (i[0]|){if (size(i)2 i[i.length()-2]!|){string content i.substr(1,size(i)-2);args.push_back(subreplace(content, %VEB%, |));}else if (size(i)2){args.push_back();}else{string content i.substr(1,size(i)-3);args.push_back(subreplace(content, %VEB%, |));// for (auto const j : args){// cout Arg: j endl;// }lineargs[nowtag] args;tinresults.push_back(lineargs);args.clear();Lines false;}}}else if (i[i.length()-2] ;){// getline最后一个为\0因此-2// string本身不以\0结尾但是getline会改成\0Lines true;bool ismatch regex_search(i, result, pattern);if (ismatch){// cout Tag: result[1] endl;nowtag result[1];string content result[2];int lastindex content.find_last_of(;);content content.substr(0, lastindex);args.push_back(subreplace(content, %VEB%, |));}else{cout \033[33;1m不可被解析当作p处理 i \033[0m endl;args.push_back(subreplace(i, %VEB%, |));lineargs[p] args;tinresults.push_back(lineargs);args.clear();}}else{bool ismatch regex_search(i, result, pattern);if (ismatch){nowtag result[1];string content result[2];auto oargs split(content, |);for (auto const j : oargs)args.push_back(subreplace(j, %VEB%, |));lineargs[nowtag] args;tinresults.push_back(lineargs);args.clear();}else{//无法匹配当作p处理cout \033[33;1m不可被解析当作p处理 i \033[0m endl;args.push_back(subreplace(i, %VEB%, |));lineargs[p] args;tinresults.push_back(lineargs);args.clear();}}}return tinresults; }这里还遇到一个坑string.getline会将分割字符转为\0这样导致string类型变量所包含的文字比表达的文字多一个“字”。string的设计是不包含的\0所以要注意从string类型中取字符的下标。 解析过程是最基础的也几乎不会再维护毕竟TinML的语法就这样了。 解释 这和TinText软件中转译html的过程一样只不过TinEngine在渲染之前就生成了解释内容并传递给了转译器而CppTinParser需要单独进行参数解释。 首先生成每个标记对应的参数含义 static mapstring, vectorstring tinkws;void loadkws() {// 标记对应的参数键tinkws[ac] {name};tinkws[anchor] {name};tinkws[code] {type, codes};tinkws[fl] {};tinkws[follow] {};tinkws[html] {htmls};tinkws[img] {name, url, size};tinkws[image] {name, url, size};tinkws[lnk] {text, url, description};tinkws[link] {text, url, description};tinkws[a] {text, url, description};tinkws[ls] {lists};tinkws[list] {lists};tinkws[n] {notes};tinkws[note] {notes};tinkws[nl] {lists};tinkws[numlist] {lists};tinkws[p] {texts};tinkws[pages] {name};tinkws[/page] {};tinkws[/pages] {};// 展示到这里位置当然这不是完整的//... }由于之前已经生成了类似如下的数据结构 ((title,(title,1),),(p,(paragraph,)),... )现在就需要把这些已经分割好的标记文本转为有意义的内容 ((title,(title: title, level: 1),),(p,(paragraph: (paragraph,))),... )这里采用的逻辑是对一个标签所拥有的所有参数一一对应多出来的统一给最后一个参数。 这部分逻辑实现如下 mapstring, string tokeywords(string tag, vectorstring contents) {// 将列表顺序参数转为键、值类参数mapstring, string keywords;cout Tag: tag endl;keywords[tag] tag;int args_num contents.size();int index 0;for (auto kws : tinkws[tag]){if (index args_num){// 剩下键全为空keywords[kws] ;continue;}keywords[kws] contents[index];// cout kws contents[index] endl;index;}if (index args_num){// 将剩下的参数全部放入最后一个键中for (int i index; i args_num; i){keywords[tinkws[tag].back()] \n contents[i];}}for (auto kw : keywords){if (kw.first tag){ // 跳过tag键continue;}cout kw.first kw.second endl;}return keywords; }class TinParser { public:TinParser(vectormapstring, vectorstring contents){this-contents contents;}void parse();void render(string file);private:vectormapstring, vectorstring contents;vectormapstring, string result; };void TinParser::parse() {// 判断tag是否存在contents this-contents;for (auto content : contents){string tag content.begin()-first;if (tinkws.find(tag) tinkws.end()){cerr \033[33;1mtag not found: tag \033[0m endl;// //string转char// char c_tag;// strcpy(c_tag, tag.c_str());// throw NoTagName(c_tag);continue;}mapstring, string results tokeywords(tag, content.begin()-second);result.push_back(results);} }转译html 经过前面的准备这里已经准备好了将TinML转译为html的所有信息。 由于在之前的文章中已经给出了HtmlRender的实现和使用示例这里便不再赘叙。 这部分的代码和TinText的tin2html.py实现在逻辑上完全一致甚至可以看作是python到c的翻译。 类定义 class TinRender {//tin-html类 public:TinRender(const string file) : file_(file){}HtmlRender* render(vectormapstring,string content, bool _style true, bool _code_style true);//转译为htmlvoid output(vectormapstring,string content);//输出 private:string file_;//html文件路径ofstream fout_;//html文件输出流 };开头html 就是html头中包含的样式、额外引入js、标题这些。 HtmlRender* TinRender::render(vectormapstring, string content, bool _style, bool _code_style){//转译为HtmlRender。可以直接使用output方法转译输出保存//注意CPPTinParser只是用c实现的tinml转译器//不作为TinML规范的检查器string tag;HtmlRender* html new HtmlRender(html, , {});HtmlRender* head new HtmlRender(head, , {});HtmlRender* title new HtmlRender(title, TinML, {});head-add(title);HtmlRender* meta new HtmlRender(meta, , {{charset,UTF-8}}, true);head-add(meta);//读取css文件if (_style){string filename blubook.css;ifstream infile;infile.open(filename.data()); //将文件流对象与文件连接起来 assert(infile.is_open()); //若失败,则输出错误消息,并终止程序运行 string s, strAllLine;while (getline(infile, s)){strAllLine s \n;}infile.close(); //关闭文件输入流HtmlRender* style new HtmlRender (style, strAllLine, {}, false, true);head-add(style);}//code样式if (_code_style){HtmlRender* codestyle new HtmlRender(link, , {{rel,stylesheet}, {type, text/css}, {href,https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/vs.min.css}});head-add(codestyle);HtmlRender* codescript new HtmlRender(script, , {{src,https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js}});head-add(codescript);HtmlRender* codestartscript new HtmlRender(script, hljs.highlightAll();, {});head-add(codestartscript);}HtmlRender* _body new HtmlRender(body, , {});HtmlRender* body new HtmlRender(div, , {{id,content}});_body-add(body);html-add(head);html-add(_body);// 提前定义类型变量HtmlRender* table;HtmlRender* tbody;bool tablehead false;HtmlRender* tabsview;bool pagestag false;vectorstring pagesnames;vectormapstring, string pagescontent;int pagescount 0;// ... }然后就是对每一个标记的单独转译这些都在上面的那个方法里这里给几个例子 // ...//常规转译TinML解析结果if (tag ac || tag anchor){string name item[name];if (name[0]#){//锚点链接HtmlRender* anchor new HtmlRender(a, , {{href, name}});HtmlRender* lastitem body-children().back();lastitem-add(anchor);}else{//锚点定义HtmlRender* anchor new HtmlRender(a, , {{id, name}});body-add(anchor);}}else if (tag code){//代码块//使用highlight.js不支持tinml代码块string type item[type];string codes item[codes];if (type tin){type nohighlight;}else{type language- type;}HtmlRender* pre new HtmlRender(pre, , {});HtmlRender* code new HtmlRender(code, codes, {{class,type}});pre-add(code);body-add(pre);}else if (tag html){//html文本string htmltext item[htmls];HtmlRender* htmlcont new HtmlRender(, htmltext, {}, false, true);body-add(htmlcont);}else if (tag img || tag image){//图片string name item[name];string url item[url];if (url.empty()){//因为CppTinParser只是用c实现的tinml转译器//不作为TinML规范的检查器也不作为tin文件渲染环境//所以不会有额外的资源文件储存位置//因此不支持从本地文件中导入图片continue;}vectorstring size render_split(item[size], x);string width size[0];string height size[1];HtmlRender* img new HtmlRender(img, , {{alt, },{src, url}, {width, width}, {height, height}});body-add(img);}// ... // ...CppTinParser甚至给对p的解析也单独移植了TinText中的逻辑 void load_para(HtmlRender* p, vectorstring lines){//添加p内容vectorchar tags {*,-,_,/,,!,^,,#};regex reg(.*?!\\[(.*)\\]\\((.*)\\));smatch result;int count 0;if (lines.size()0){//空行HtmlRender* br new HtmlRender(br, , {}, true);p-add(br);return;}for (auto line : lines) {HtmlRender* last p;//p最后一个元素if (line[0] ){//空格string text line.substr(1);HtmlRender* p_item new HtmlRender(, text, {});p-add(p_item);continue;}string head;if (line.size() 9){head line;}else{head line.substr(0, 9);}//p开头标记需要连续count 0;for (auto tag_char : head){if (find(tags.begin(), tags.end(), tag_char) ! tags.end()){count;}else{break;}}head head.substr(0, count);if (count 0){HtmlRender* p_item new HtmlRender(, line, {});p-add(p_item);continue;}if (head.find(*)!string::npos){HtmlRender* nowlast new HtmlRender(b, , {});last-add(nowlast);last nowlast;}if (head.find(/)!string::npos){HtmlRender* nowlast new HtmlRender(i, , {});last-add(nowlast);last nowlast;}if (head.find(_)!string::npos){HtmlRender* nowlast new HtmlRender(u, , {});last-add(nowlast);last nowlast;}if (head.find(-)!string::npos){HtmlRender* nowlast new HtmlRender(s, , {});last-add(nowlast);last nowlast;}if (head.find()!string::npos){// 和 # 只能存在一个HtmlRender* nowlast new HtmlRender(mark, , {});last-add(nowlast);last nowlast;}else if (head.find(#)!string::npos){HtmlRender* nowlast new HtmlRender(code, , {});last-add(nowlast);last nowlast;}if (head.find(^)!string::npos){// ^ 和 只能存在一个HtmlRender* nowlast new HtmlRender(sup, , {});last-add(nowlast);last nowlast;}else if (head.find()!string::npos){HtmlRender* nowlast new HtmlRender(sub, , {});last-add(nowlast);last nowlast;}if (head.find(!)!string::npos){bool ismatch regex_match(line, result, reg);if (ismatch) {string text result[1];string url result[2];if (text ){text url;}HtmlRender* p_item new HtmlRender(a, text, {{href,url}});last-add(p_item);}else{string text line.substr(count);HtmlRender* p_item new HtmlRender(, text, {});last-add(p_item);}}else{last-configcnt(line.substr(count));}} }结果 这里用的是TinText项目中的test.tin。效果上来看除了code中对TinML的缺失以及对在线图片、tinfile不支持外其他几乎一样而且对于大文件的转译绝对比python实现要快。 这是源文件部分 这是最终效果部分
http://www.dnsts.com.cn/news/221738.html

相关文章:

  • 全球访问量最大的10个网站北京南站核酸检测地点
  • 网站网页设计专业公司阜阳哪里有做网站的
  • 教育网站制作论文建设企业网站需要多少钱
  • 个人网站鉴赏织梦网站模板本地安装教程
  • 专业网站建设定制现在的网站推广是怎么做的
  • 做网站在国外发图片必知的网站
  • 温州自助模板建站无锡做网站公司哪家比较好
  • 如何对网站的图片做cdn淘客做的领券网站
  • joomla 做外贸网站 好的专业网络推广公司
  • 在网上如何找做网站的人中国十大小说网站排名
  • dw做网站导航条wordpress用户同步
  • 陌上香坊是做盗版的网站吗wordpress二级域名使用七牛
  • 网站建站软件泰安中文网站建设电话
  • 番禺网站建设公司哪家好网站建设合同 含维护费
  • 南充外贸网站建设百度app小程序
  • 做一个网站花多少钱百度收录提交查询
  • 龙岗专业网站建设开源无代码开发平台
  • 新余哪有做网站的公司网站优化具体是怎么做的
  • 如何做网站么广西工程造价信息网
  • 网站后期维护费用wordpress在手机登录
  • 慈溪网站建设创办网站公司
  • 网站加在线qq接网站做项目赚钱吗
  • 用dw怎么做网站中天建设集团有限公司营业执照
  • 专业网站开发软件网站 怎么备案
  • 网站怎么添加广告drupal wordpress 性能
  • 不备案的网站需要注销吗做商业网站是否要备案
  • 哪个网站可以做会计题专业团队歌曲
  • 个人网站制作手绘wordpress更新一直下载
  • 服务器 网站打开慢cpanel做wordpress
  • 品牌推广网站策划设计品牌网站建设价位