iT邦幫忙

0

別人寫了將mxml轉成html,而我又寫了html轉成更好的html

  • 分享至 

  • xImage
  •  

一開始寫是因為別人轉的內容就差一點點,可以我卻要多花五分鐘去調整內容,覺得很煩,所以我再寫一個轉檔程式。

1.加分號:

fname=fname.replace(new RegExp("</systex-label>",'g'),"</systex-label><span>:</span>");

2ModuleConsts改成moduleConsts

fname=fname.replace("formManagementAfterViewInit($event)","formManagementAfterViewInit()");

3加入欄位的寬度

if(array[i].indexOf('[maxlength]')>=0 && array[i].indexOf('[width]')==-1){
	var indexOf1=array[i].indexOf('[maxlength]');
	var indexOf2=array[i].indexOf('	');
	var width=array[i].substring(indexOf1+12,indexOf1+15);
	width=width.replace(new RegExp("\"",'g'),"");
	array[i]=array[i].replace('<systex-text-input','          <systex-text-input \n            [width]=\"'+width*15+'\"');
}else if(array[i].indexOf('[maxlength]')>=0 && /\[width\].+%./.test(array[i])){
	array[i]=array[i].replace(/\[width\].+%./,"");
	var indexOf1=array[i].indexOf('[maxlength]');
	var indexOf2=array[i].indexOf('	');
	var width=array[i].substring(indexOf1+12,indexOf1+15);
	width=width.replace(new RegExp("\"",'g'),"");
	array[i]=array[i].replace('<systex-text-input','          <systex-text-input \n            [width]=\"'+width*15+'\"');
}

4新舊程式的替換

array[i].replace('style="color: red"','[fontColor]="true"'

最後完成的程式如下:


<!doctype html>
<html lang="zh" dir="ltr">
<head></head>
<body>

	<button onclick="f()">change</button>
	<button onclick="clearAll()">clear</button>
	
	<form>
	<div  style="display: flex; flex-direction: row;">
	
	<div  style="width: 100%;">
	<h3 >HTML</h3>
	<textarea  rows="30" style="width: 95%;" id="fname"></textarea>
	</div>
	
	<div style="width: 100%;">
	<h3 >HTML2</h3>
	<textarea  rows="30" style="width: 95%;" id="fname2"></textarea>
	</div>
	</div>
	
	</form>
	<script language="javascript">
		function f(){
			var fname=document.getElementById('fname').value;
			fname=fname.replace(new RegExp("</systex-label>",'g'),"</systex-label><span>:</span>");
			fname=fname.replace("formManagementAfterViewInit($event)","formManagementAfterViewInit()");
			fname=fname.replace(new RegExp("ModuleConsts",'g'),"moduleConsts");
			<!--//<systex-reverse-label id="RL">,<systex-reverse-label id="RL" [dbcrFlag]="dbcrFlag" [reverseFlag]="ReversalFlag">-->
			fname=fname.replace(new RegExp("<systex-reverse-label id=\"RL\"",'g'),"<systex-reverse-label id=\"RL\" [dbcrFlag]=\"dbcrFlag\" [reverseFlag]=\"ReversalFlag\" ");
			
			<!--//<systex-reverse-group id="RG">,<systex-reverse-group id="RG" (reverseKeydown)="onBDSCPTReverseKeydown($event)">-->
			fname=fname.replace(new RegExp("<systex-reverse-group id=\"RG\"",'g'),"<systex-reverse-group id=\"RG\" (reverseKeydown)=\"onBDSCPTReverseKeydown($event)\" ");
			fname=fname.replace(new RegExp("<div class=\"transaction-form\">",'g'),"<div class=\"transaction-form\">               <div class=\"group-body\">               ");	
			fname=fname.replace(new RegExp("<div class=\"transaction-spacer\">",'g'),"    </div>    <div class=\"transaction-spacer\">");
			
			fname=fname.replace(new RegExp("<systex-text-input",'g'),"@<systex-text-input");
			fname=fname.replace(new RegExp("</systex-text-input>",'g'),"</systex-text-input>@");

			var array=fname.split("@");
		
			var str="";
			for(var i=0;i<array.length;i++){
				if(array[i].indexOf('<systex-text-input')>=0){
					if(array[i].indexOf('[maxlength]')>=0 && array[i].indexOf('[width]')==-1){
						var indexOf1=array[i].indexOf('[maxlength]');
						var indexOf2=array[i].indexOf('	');
						var width=array[i].substring(indexOf1+12,indexOf1+15);
						width=width.replace(new RegExp("\"",'g'),"");
						array[i]=array[i].replace('<systex-text-input','          <systex-text-input \n            [width]=\"'+width*15+'\"');
					}else if(array[i].indexOf('[maxlength]')>=0 && /\[width\].+%./.test(array[i])){
						array[i]=array[i].replace(/\[width\].+%./,"");
						var indexOf1=array[i].indexOf('[maxlength]');
						var indexOf2=array[i].indexOf('	');
						var width=array[i].substring(indexOf1+12,indexOf1+15);
						width=width.replace(new RegExp("\"",'g'),"");
						array[i]=array[i].replace('<systex-text-input','          <systex-text-input \n            [width]=\"'+width*15+'\"');
					}
					if(array[i].indexOf('style="color: red"')>=0){
						array[i]=array[i].replace('style="color: red"','[fontColor]="true"');
					}
				}
				str+=array[i]+"\n";
			}
			if(str.lastIndexOf('transaction-area') !=str.indexOf('transaction-area')){
				var indexOf3=str.lastIndexOf('transaction-area');
				var str2=str.substring(0,indexOf3-14)+"</systex-form-management>";
				document.getElementById('fname2').value = str2;	
			}else{
				document.getElementById('fname2').value = str;
			}
		}

		function clearAll(){
			document.getElementById('fname2').value='';
			document.getElementById('fname').value='';
		}
		
	</script>
</body>
</html>

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言