Applescript Wrap Lines With Html Tags And Marsedit.app Script Problem
Im currently using a script in MarsEdit.app which has a flaw. It checks the HTML document for cases where paragraphs are wrapped with
tags as follows: -- If already start
Solution 1:
AppleScript:
tell application "MarsEdit"toset txt to current textof document 1set paras to paragraphs of txt
repeat with i from1to (count paras)
set v to item i of paras
ignoring white space
ifnot (v is""or v starts with"<") thenset item i of paras to"<p>" & v & "</p>"endifend ignoring
end repeat
settext item delimiters to ASCII character 10
tell application "MarsEdit"toset current textof document 1to paras astext
require'appscript'; include Appscript
doc = app('MarsEdit').documents[0]
lines = doc.current_text.get.gsub(/\r\n?/, "\n").split("\n")
for i in0...lines.size
nextiflines[i] =~ /^\s*$/ orlines[i] =~ /^\s*</
lines[i] = "<p>#{lines[i]}</p>"end
doc.current_text.set(lines.join("\n"))
These assume that anything starting with (white space and) <
is a tag.
Solution 2:
you could do this process using another stronger language by running shell commands in applescript
basiclly you can run anything that you would in a terminal window like this
lets assume you have a test.txt file on your desktop you could run this and it would wrap all the lines with p tag
set dir to quoted form of POSIX path of (path to desktop)
set results to do shell script "cd "& dir &"
awk ' { print \"<p>\"$0\"</p>\" } ' test.txt"
and if you want to run a php file you just do
set dir to quoted form of POSIX path of 'path:to:php_folder")
set results to do shell script "cd " & dir & "
php test.php"
Post a Comment for "Applescript Wrap Lines With Html Tags And Marsedit.app Script Problem"