html tags to paragraph styles

Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

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?

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

TOPICS
How to, Scripting, Type

Views

64

Likes

Translate

Translate

Report

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

html tags to paragraph styles

Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

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?

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

TOPICS
How to, Scripting, Type

Views

65

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 15, 2020 0
Adobe Community Professional ,
Jul 15, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 0
Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 0
Enthusiast ,
Jul 15, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 1
lmronan! LATEST
Community Beginner ,
Jul 15, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 15, 2020 1