Applescript:在span标签内剪切字符和粘贴

时间:2017-05-26 13:55:13

标签: applescript textwrangler

我已经自动执行了一项流程,我们的工作涉及将Word文档转换为TextWrangler中的html文件。除了最后一步之外,我已经对所有内容进行了排序,其中包括将文章的第一个字符移到span标签内(Boss的设计选择,并且该网站不支持CSS不是&#39 ; t inline或我只使用第一个字母)。

无论如何,HTML看起来像这样:

<p style='color: #444; font-size: 1.4em; line-height: 1.8em; font-weight: bold;'>
<img style='display: block; float: right; margin-bottom: 30px; margin-left: 15px; width: 475px;' src='*****.jpg' alt='' width='950' height='713' />
<span style='color: #444; float: left; font-size: 3em;'></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer at rhoncus velit. Sed velit libero, venenatis non ornare ac, egestas vitae quam.</p>

这个想法只是将关闭范围标记后面的第一个字母移动到span标记内部,但我已经环顾四周,并且不知道从哪里开始。

编辑:这可能会变得更容易,因为知道该行中必要字母之前的字符数不会发生变化。那么也许找到一种方法来隔离该行中的第n个字符并从那里开始?

1 个答案:

答案 0 :(得分:0)

这是一个愚蠢的例子,你需要稍微改进一下:

set htmlText to "... your HTML ..."

set endSpanLength to 7
set endSpanPos to offset of "</span>" in htmlText
set firstCharPos to (endSpanPos + endSpanLength + 1)
set firstChar to character firstCharPos of htmlText

set oldEndSpan to "</span>" & linefeed & firstChar
set newEndSpan to firstChar & "</span>" & linefeed

findAndReplaceInText(htmlText, oldEndSpan, newEndSpan)

on findAndReplaceInText(theText, theSearchString, theReplacementString)
    set AppleScript's text item delimiters to theSearchString
    set theTextItems to every text item of theText
    set AppleScript's text item delimiters to theReplacementString
    set theText to theTextItems as string
    set AppleScript's text item delimiters to ""
    return theText
end findAndReplaceInText