Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. Lookup[NotebookInformation[nb], "StyleDefinitions", {}]
  2.  
  3. processSheet // Clear
  4. processSheet[{nb_NotebookObject, {implements_NotebookObject, ___}}] :=
  5. implements;
  6. processSheet[_] := Nothing;
  7. getSheet // Clear;
  8. getSheet[nb_NotebookObject] :=
  9.  
  10. processSheet@Lookup[NotebookInformation[nb], "StyleDefinitions", {}];
  11. getSheet[e_] := e;
  12. getStyleSheetChain[nb_NotebookObject] :=
  13. Rest@
  14. Module[{s = <||>},
  15. FixedPointList[
  16. getSheet,
  17. Replace[Lookup[NotebookInformation[nb], "StyleDefinitions", {}],
  18. {
  19. {n_NotebookObject} :> n,
  20. {n_NotebookObject, {i_, ___}} :> i
  21. }
  22. ]
  23. ]
  24. ]
  25.  
  26. mergeStyles[styles_]:=
  27. Merge[
  28. {
  29. styles
  30. },
  31. If[AnyTrue[#, ListQ[#]&&OptionQ[#]&],
  32. Merge[Flatten@#, Last],
  33. Last@#
  34. ]&
  35. ];
  36. mergeStyleSet[styles_]:=
  37. Merge[
  38. Normal/@styles,
  39. mergeStyles
  40. ];
  41.  
  42. getStyleChain[nbs:{__NotebookObject}]:=
  43. Module[
  44. {
  45. cells=Cells/@nbs,
  46. names,
  47. ops
  48. },
  49. ops=ConstantArray[<||>, Length@nbs];
  50. MapIndexed[
  51. Replace[
  52. #,
  53. {
  54. Cell[StyleData[name:_String|All, env:_String|None:None], o___?OptionQ]:>
  55. Set[
  56. ops[[#2[[1]], Key@If[env===None, name, {name, env}] ]],
  57. Merge[
  58. {
  59. Normal@Replace[
  60. ops[[#2[[1]], Key@If[env===None, name, {name, env}]]],
  61. Except[_Association]:><||>
  62. ],
  63. o
  64. },
  65. Last
  66. ]
  67. ],
  68. c:Cell[
  69. StyleData[
  70. name:_String|All, env:_String|None:None,
  71. StyleDefinitions->StyleData[parent_]
  72. ],
  73. o___?OptionQ
  74. ]:>
  75. With[
  76. {
  77. inherited=
  78. mergeStyles@
  79. Flatten@List@Lookup[ops[[;;#2[[1]]-1]], Key@parent, <||>]
  80. },
  81. Set[
  82. ops[[#2[[1]],Key@If[env===None, name, {name, env}] ]],
  83. Merge[
  84. {
  85. Replace[
  86. ops[[#2[[1]], Key@If[env===None, name, {name, env}]]],
  87. Except[_Association]-><||>
  88. ],
  89. o
  90. },
  91. Last
  92. ]
  93. ]
  94. ]
  95. },
  96. 1
  97. ]&,
  98. NotebookRead/@cells
  99. ];
  100. mergeStyleSet@ops
  101. ]
  102.  
  103. getStyleSheetChain[EvaluationNotebook[]]
  104.  
  105. styles = getStyleChain[getStyleSheetChain[EvaluationNotebook[]]];
  106.  
  107. styles["CodeText"]
  108.  
  109. <|CellMargins -> {{66, 10}, {3, 15}}, LineSpacing -> {1, 1, 1},
  110. MenuSortingValue -> 1540, FontColor -> GrayLevel[0.45]|>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement