Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

html tags to paragraph styles

Community Beginner ,
Jul 15, 2020 Jul 15, 2020

I have a Word doc with some simple html tags, ie. <CT> for the chapter title. Is there a way for me to globally change the paragraph following the tag to a existing paragraph style?

TOPICS
How to , Scripting , Type
663
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jul 15, 2020 Jul 15, 2020

Brian is right. Find/Change will do the job. You can also use a script to do this.

Does the paragraph styles names the same of the tag content?

If yes, you can use this:

//DESCRIPTION: Apply pStyle based on tag
//=============================================================
//  Script by Luis Felipe Corullón
//  Contato: lf@corullon.com.br
//  Site: http://scripts.corullon.com.br
//  +55 (51) 9-9685.7565
//  Version: 20200715_2128_GMT-3
//============================================================
...
Translate
Community Expert ,
Jul 15, 2020 Jul 15, 2020

Find/Replace should do. Find the tag, replace with the same tag and change the paragraph style to the desired one? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 15, 2020 Jul 15, 2020

Thank you. That would certainly work, but I am looking for a quicker, more global way of approaching this. A year or so ago I had found a script, lost it, and can't seem to google it up, again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 15, 2020 Jul 15, 2020

Brian is right. Find/Change will do the job. You can also use a script to do this.

Does the paragraph styles names the same of the tag content?

If yes, you can use this:

//DESCRIPTION: Apply pStyle based on tag
//=============================================================
//  Script by Luis Felipe Corullón
//  Contato: lf@corullon.com.br
//  Site: http://scripts.corullon.com.br
//  +55 (51) 9-9685.7565
//  Version: 20200715_2128_GMT-3
//=============================================================

var myScriptName = "Apply pStyle based on tag";
var myIDversion = app.version.split(".")[0];
if (!app.documents.length || (app.documents.length && !app.documents[0].visible)) {
    alert("There is no opened document." , "Script by LFCorullón" , true);
    }
else {
    if (myIDversion < 6) main();
    else app.doScript(main, ScriptLanguage.javascript, undefined, UndoModes.entireScript, myScriptName);
    }

function main() {
	var doc = app.activeDocument;
	
	app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
	app.findGrepPreferences.findWhat = "<.+?>";
	var f = doc.findGrep();
	app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
	
	for (var i=0; i<f.length; i++) {
		var c = f[i].contents.replace(/<|>/g , "");
		for (var j=0; j<doc.allParagraphStyles.length; j++) {
			if (doc.allParagraphStyles[j].name == c) {
				f[i].appliedParagraphStyle = doc.allParagraphStyles[j];
				}
			}
		}
		
    }

 

Video_2020-07-15_212932.gif

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 15, 2020 Jul 15, 2020
LATEST

I do believe this is the script. Thank you so very much!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines