Skip to main content
davidc88034496
Known Participant
November 11, 2021
해결됨

Replacing "SHIFT+ENTER" aka ETX aka <0x03> aka End-of-Transmission character within TEXT LAYERS

  • November 11, 2021
  • 2 답변들
  • 1324 조회

Hello, i basically have this huge script that converts artboards into HTML.  It works great, however, im having an issue with TEXT LAYERS.

 

When we either copy and paste some text layers from Photoshop onto Sublime Text Editor, we can see the hex value "<0x03>" and when we paste into Visual Studio Code, we see a block image that says ETX. 

 

I have found that this is caused by hitting "Shift+Enter" when creating a new line in TEXT LAYERS.

 

Right now i wish to update my Adobe Photoshop JavaScript script to eliminate those ETX symbols aka <0x03>

 

im using the code below to go into every TEXT LAYER and rename them to a different line carriage. "\r\n".

 

If anyone can help that would be great thank you!

 

if (layers[d].typename == "ArtLayer") {
    if (layers[d].kind == LayerKind.TEXT) {
      layers[d].textItem.contents.replace(/<0x03>|0x03|ETX/gmi, '\r\n');
    }
}
이 주제는 답변이 닫혔습니다.
최고의 답변: Kukurykus

You can check where and what kind of hidden characters are located by using this:

 

activeDocument.activeLayer.textItem.contents.toSource()

 

2 답변

Legend
November 11, 2021
quote
if (layers[d].typename == "ArtLayer") {
    if (layers[d].kind == LayerKind.TEXT) {
      layers[d].textItem.contents.replace(/<0x03>|0x03|ETX/gmi, '\r\n');
    }
}

By @davidc88034496

 

1. Invalid RegExp

2. No result assigned to text layer content

 

davidc88034496
Known Participant
November 11, 2021

yes yes thanks for pointing that out.  I was able to rewrite the final code as follows.  Thank you

 

if (layers[d].typename === "ArtLayer") {
    if (layers[d].kind === LayerKind.TEXT) {
        var etxRegEx = /\\x03/gmi;
        if (layers[d].textItem.contents.toSource().match(etxRegEx)) {
          var sourceText=layers[d].textItem.contents.toSource().slice(13,-3);
          layers[d].textItem.contents = sourceText.replace(/\\x03/gmi, '\r');
        }
    }
}

 

Kukurykus
Legend
November 11, 2021

Your regex should work witout m parameter.

Kukurykus
Kukurykus답변
Legend
November 11, 2021

You can check where and what kind of hidden characters are located by using this:

 

activeDocument.activeLayer.textItem.contents.toSource()

 

davidc88034496
Known Participant
November 11, 2021

hey thanks i was able to see the hidden characters but how do i apply the hidden characters i tried to do the below but it prevents my script from running.

activeDocument.activeLayer.textItem.contents.toSource() = activeDocument.activeLayer.textItem.contents.toSource().replace(/\\x03/gmi, '')

if try the below then i see the actual hidden characters showing in my TEXT LAYER content.  How do i replace theSource()?

activeDocument.activeLayer.textItem.contents = activeDocument.activeLayer.textItem.contents.toSource().replace(/\\x03/gmi, '')

Thank

Kukurykus
Legend
November 11, 2021

You can't use replacing on sourced text, first you have to get rid of that part by:

 

cntnt = 'someText'.toSource().slice(13, -3)