console
document.getElementById('btn').addEventListener('click', function() {
let text = document.getElementById('text').value;
// 去掉所有引号内的空格
text = text.replace(/"\s*([^ "]*)\s*"/, '"$1"');
// 去掉所有tab、多个空格
text = text.replace(/\s+/, ' ');
// alert(text);
// 拼接snl
let result = `
<?xml version="1.0" encoding="UTF-8"?>
<rule_lib>
<lib_name>单条合并.snl</lib_name>
<lib_info />
<ontology />
<class_set>
<class id="0">
<class_name>所有规则</class_name>
<class_number />
</class>
<class id="0,1">
<class_name>分类1</class_name>
<class_number>1</class_number>
</class>
<class id="0,0">
<class_name>未分类</class_name>
<class_number />
</class>
</class_set>
<resource_set />
<group_set>
<group_introduction />
</group_set>
<rule_set>
<rule_introduction />
<rule id="1">
<whichclass>0,1</whichclass>
<rule_number>1</rule_number>
<resourceName>;</resourceName>
<rule_group />
<rule_nat_descpt>规则1</rule_nat_descpt>
<rule_anot_descpt />
</rule>
</rule_set>
<fml_descpt_set>
${
text.split('\n').map((row, i) => {
return `
<fml_descpt id="${i+1}">
<ruleId>${i+1}</ruleId>
<descpt_snl>${row}</descpt_snl>
<descpt_snl_split_text />
</fml_descpt>
`;
}).join('\n')
}
<fml_descpt id="1">
<ruleId>1</ruleId>
<descpt_snl>所有 建筑 有 门</descpt_snl>
<descpt_snl_split_text />
</fml_descpt>
<fml_descpt id="2">
<ruleId>1</ruleId>
<descpt_snl>所有 建筑 有 门</descpt_snl>
<descpt_snl_split_text />
</fml_descpt>
</fml_descpt_set>
<temporal_descpt_set />
<note_set />
<config_set text="墙 = {ifc2x3:ifcwall,ifc2x3:ifcwallstandardcase}
门 = {ifc2x3:ifcdoor,ifc2x3:ifcdoorstandardcase}
洞口 = ifc2x3:ifcopeningelement
窗 = ifc2x3:ifcwindow
楼梯 = ifc2x3:ifcstair
坡道 = ifc2x3:IfcRamp
天花板 = {ifc2x3:ifcceiling,ifc2x3:IfcCovering}
家具 = ifc2x3:IfcFurniture
家具系统 = ifc2x3:IfcSystemFurnitureElement
房间 = ifc2x3:IfcSpace
空间 = ifc2x3:IfcSpace
柱 = ifc2x3:IfcColumn
梁 = ifc2x3:ifcbeam
栏杆扶手 = ifc2x3:IfcRailing
楼板 = ifc2x3:IfcSlab
橱柜 = ifc2x3:IfcFurniture
屋顶 = ifc2x3:IfcRoof
幕墙 = ifc2x3:IfcCurtainWall
标高 =ifc2x3:IfcBuildingStorey
楼层 =ifc2x3:IfcBuildingStorey
管道 = ifc2x3:ifcpipesegment
管件 = ifc2x3:ifcpipefitting
管道附件 = {ifc2x3:ifcpipevalve,ifc2x3:ifcvalve}
管道隔热层 = {ifc2x3:ifcpipecovering,ifc2x3:ifccovering}
软管 = ifc2x3:ifcpipesegment
线管 = ifc2x3:ifccablepipesegment
线管配件 = ifc2x3:ifccablepipefitting
电缆桥架 = ifc2x3:ifccablecarriersegment
电缆桥架配件 = ifc2x3:ifccablecarrierfitting
风管 = ifc2x3:IfcDuctSegment
软风管 = ifc2x3:IfcDuctSegment
风管隔热层 = {ifc2x3:ifcductcovering,ifc2x3:ifccovering}
风管管件 = ifc2x3:IfcDuctFitting
风道末端 = ifc2x3:IfcAirTerminal
风管附件 = {ifc2x3:ifcductvalve,ifc2x3:ifcvalve}
风管系统 = {ifc2x3:ifcductsystem,ifc2x3:ifcsystem}
管道系统 = {ifc2x3:ifcpipesystem,ifc2x3:ifcsystem}
照明设备 = ifc2x3:ifclightfixture
卫浴装置 = ifc2x3:ifcsanitaryterminal
机械设备 = {ifc2x3:ifcmechanicalappliance,ifc2x3:ifcbuildingelementproxy}
电话设备 = ifc2x3:IfcElectricAppliance
火警设备 = ifc2x3:IfcAlarm
结构基础 = ifc2x3:IfcFooting
结构柱 = ifc2x3:IfcColumn
结构框架 = {ifc2x3:ifcstructuralframe,ifc2x3:ifcbuildingelementproxy}
结构钢筋网 = ifc2x3:IfcReinforcementMesh
结构钢筋网区域 = ifc2x3:IfcGroup
结构梁系统 = ifc2x3:IfcAssembly
结构桁架 = ifc2x3:IfcAssembly
结构钢筋 = ifc2x3:IfcReinforcingMesh
结构区域钢筋 = ifc2x3:IfcReinforcingBar
结构路径钢筋 = ifc2x3:IfcReinforcingBar
常规模型 = {ifc2x3:model,ifc2x3:ifcbuildingelementproxy}
场地 = ifc2x3:IfcSlab
组成部分 = ifc2x3:IfcBuildingElementPart
喷头 = ifc2x3:IfcFireSuppressionTerminal
数据设备 = ifc2x3:IfcElectricAppliance
护理呼叫设备 = ifc2x3:IfcSwitchingDevice
专用设备 = {ifc2x3:ifcspecialappliance,ifc2x3:IfcBuildingElementProxy}
建筑 = ifc2x3:ifcbuilding
面积 = ifc2x3:ifcarea
" />
<alias_set text="" />
<selected_rules />
</rule_lib>`;
// 提供下载
let filename = '单条合并.snl';
var blob = new Blob([result], {type: 'text/plain'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
});
粘贴SNL内容(一行一个)<br />
<textarea id="text">
</textarea>
<br />
<button id="btn">
生成
</button>