Skip to main content

Another Highlighter: Prism


Prism is another highlighter, which is designed to meet the modern standard.

To extend the functionality of Prism and to add a new language support for Prism are not difficult.

Here are examples of three different highlighters:

Prism
#targetengine "session"

main();
function main() {
 StyleSetup();
 myWorking();
 myCleanup();
}

function StyleSetup() {
 var myDocument;
 if (app.documents.length == 0) {
  myDocument = app.documents.add();
 } else {
  myDocument = app.documents.item(0);
 }

 myCompsiteFontsSetup(myDocument);
}

function myWorking() {
}

function myCleanup() {
}

// ===== Composite Fonts ==================================
function SetupOneCompFont(myDocument, nFName, nHanName, nHanStyle, nRomName, nRomStyle) {
 var nCF = myDocument.compositeFonts.item(nFName);
 try {
  var myName = nCF.name;
 }
 catch (myError) {
  nCF = myDocument.compositeFonts.add();
  with (nCF) {
   name = nFName;
   var idx;
   for (idx = 0; idx < 3; idx++) {
    //console.log('Walking east one step');
    with (compositeFontEntries.item(idx)) {
     appliedFont = app.fonts.item(nHanName);//nHanName;
     fontStyle = nHanStyle;
    }
   }
   for (idx = 3; idx < 5; idx++) {
    with (compositeFontEntries.item(idx)) {
     appliedFont = app.fonts.item(nRomName); //nRomName;
     fontStyle = nRomStyle;
    }
   }
  }
 }
}

function myCompsiteFontsSetup(myDocument) {
 try {
  SetupOneCompFont(myDocument, "明體 - Caribi", "文鼎明體", "Medium", "Calibri", "Regular");
 }
 catch (theError) {
 }

 try {
  SetupOneCompFont(myDocument, "隸書 - Times", "文鼎隸書", "Bold", "Times New Roman", "Regular");
 }
 catch (theError2) {
 }
}


Syntaxhighlighter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#targetengine "session"
 
main();
function main() {
 StyleSetup();
 myWorking();
 myCleanup();
}
 
function StyleSetup() {
 var myDocument;
 if (app.documents.length == 0) {
  myDocument = app.documents.add();
 } else {
  myDocument = app.documents.item(0);
 }
 
 myCompsiteFontsSetup(myDocument);
}
 
function myWorking() {
}
 
function myCleanup() {
}
 
// ===== Composite Fonts ==================================
function SetupOneCompFont(myDocument, nFName, nHanName, nHanStyle, nRomName, nRomStyle) {
 var nCF = myDocument.compositeFonts.item(nFName);
 try {
  var myName = nCF.name;
 }
 catch (myError) {
  nCF = myDocument.compositeFonts.add();
  with (nCF) {
   name = nFName;
   var idx;
   for (idx = 0; idx < 3; idx++) {
    //console.log('Walking east one step');
    with (compositeFontEntries.item(idx)) {
     appliedFont = app.fonts.item(nHanName);//nHanName;
     fontStyle = nHanStyle;
    }
   }
   for (idx = 3; idx < 5; idx++) {
    with (compositeFontEntries.item(idx)) {
     appliedFont = app.fonts.item(nRomName); //nRomName;
     fontStyle = nRomStyle;
    }
   }
  }
 }
}
 
function myCompsiteFontsSetup(myDocument) {
 try {
  SetupOneCompFont(myDocument, "明體 - Caribi", "文鼎明體", "Medium", "Calibri", "Regular");
 }
 catch (theError) {
 }
 
 try {
  SetupOneCompFont(myDocument, "隸書 - Times", "文鼎隸書", "Bold", "Times New Roman", "Regular");
 }
 catch (theError2) {
 }
}


code prettifier
  1. #targetengine "session"
  2.  
  3. main();
  4. function main() {
  5. StyleSetup();
  6. myWorking();
  7. myCleanup();
  8. }
  9.  
  10. function StyleSetup() {
  11. var myDocument;
  12. if (app.documents.length == 0) {
  13. myDocument = app.documents.add();
  14. } else {
  15. myDocument = app.documents.item(0);
  16. }
  17.  
  18. myCompsiteFontsSetup(myDocument);
  19. }
  20.  
  21. function myWorking() {
  22. }
  23.  
  24. function myCleanup() {
  25. }
  26.  
  27. // ===== Composite Fonts ==================================
  28. function SetupOneCompFont(myDocument, nFName, nHanName, nHanStyle, nRomName, nRomStyle) {
  29. var nCF = myDocument.compositeFonts.item(nFName);
  30. try {
  31. var myName = nCF.name;
  32. }
  33. catch (myError) {
  34. nCF = myDocument.compositeFonts.add();
  35. with (nCF) {
  36. name = nFName;
  37. var idx;
  38. for (idx = 0; idx < 3; idx++) {
  39. //console.log('Walking east one step');
  40. with (compositeFontEntries.item(idx)) {
  41. appliedFont = app.fonts.item(nHanName);//nHanName;
  42. fontStyle = nHanStyle;
  43. }
  44. }
  45. for (idx = 3; idx < 5; idx++) {
  46. with (compositeFontEntries.item(idx)) {
  47. appliedFont = app.fonts.item(nRomName); //nRomName;
  48. fontStyle = nRomStyle;
  49. }
  50. }
  51. }
  52. }
  53. }
  54.  
  55. function myCompsiteFontsSetup(myDocument) {
  56. try {
  57. SetupOneCompFont(myDocument, "明體 - Caribi", "文鼎明體", "Medium", "Calibri", "Regular");
  58. }
  59. catch (theError) {
  60. }
  61.  
  62. try {
  63. SetupOneCompFont(myDocument, "隸書 - Times", "文鼎隸書", "Bold", "Times New Roman", "Regular");
  64. }
  65. catch (theError2) {
  66. }
  67. }

Comments