我正在使用不支持嵌入式样式或CSS输入的旧系统。要与该系统兼容,需要将大量HTML文件转换为特定格式。
因此,我正在寻找一种方法,以编程方式将多个标签的内联样式转换为具有相关属性的单个字体标签。
可以做到吗?例如:
<p style="color: #000; font-family: arial,helvetica,sans-serif; font-size: 10px; font-weight: bold;">Text</p>
<!-- Converted to: -->
<font color="#000" face="arial,helvetica,sans-serif" size="10px" weight="bold"><p>Text</p></font>
编辑:不是What tag should I use instead of deprecated tag font in html (cannot use CSS)的重复项。由于样式属性在旧版系统中被剥离,因此我没有在寻找字体标记的替代方法。
答案 0 :(得分:1)
是的,可以做到。您需要一种可编程的脚本语言,该语言可以读取/写入文本文件,执行基本逻辑,循环等。有多种选择,但难度有所不同。示例包括:
为了易于使用,我的偏好设置按以下顺序排列:6、3、5、1、4、2、7。
选择一个,然后开始尝试执行该项目,然后返回并向我们寻求更多帮助。基本上,伪代码算法可能看起来像这样:
arr = array_of_the_html_filenames
for i = 1 to len(arr) //i.e. do this for each filename
next_file_name = arr[i]
func_process_this_file(next_file_name)
next
func_process_this_file(file_name)
input_file_name = file_name
output_file_name = parse input_file_name string to create an output_file_name
hFIN = fileOpen(input_file_name, "read") #get fileHandle for next file
hFOUT = fileOpen(output_file_name, "write")
next_line = fileRead(hFIN) //read next_line of current file as a string
while next_line !== "EOF"
out_line = ''
if next_line == EOF: break
if next_line contains "font-family":
font_data = parse the string to get the data for the font tag
rest_of_string_with_font_data_removed = parse string to extract all except font data
out_line = "<font>" + font_data + "</font>" + rest_of_string_with_font_data_removed
file_write(hFOUT, out_line)
else
out_line = next_line
file_write(hFOUT, out_line)
endif
next_line = fileRead(hFIN) //read next_line of current file as a string
endwhile
file_close(hFIN)
file_close(hFOUT)
return