MD files and automatic insertions (CSS-linkage, TOC-strings) – possible?

@lerone this won‘t work. Adding this is not sufficient to change a normal script into a Smart Rule script. Please compare the scripts in the other thread to see what’s needed (hint: Smart Rule scripts don’t process selected records)

1 Like

@Bluefrog thx for persisting! there are some advances I can make w/ the script of @chrillek – so, only if it doesn´t clock too much time… in any way the general attendance is appreciated.Entry_example.zip (371 Bytes)

@chrillek - sorry I was sparse on details. it is all for me like opening up a swiss clock, and loosing myself in its intricate mechanism. so, thx for the follow-up even more!

actually my problem as uninitiated was that I didn´t see the script-editor has that choice-palette for apple-script vs. js – … it only appeared after toggling the display panes of the editor via display-menu (so basically you have to know it´s there)…
but now I am one bit clearer on JS-use in DT :-}

basically: the CSS-insert now works in principle! many 'thank you’s!
detailed experience:

– the CSS-insert this way works one time. meaning once the script worked on a document it appends any future change, leaving the first CSS-insert remaining the effective one.
this is of course ok (and something I didn´t initially figure in the equation). it simply means one has to be aware for logistics that this is a one-time shot (also maybe as flagging for others who possibly use this)

– the TOC-insertion doesn´t work here, though blank lines are inserted. TOC is not.
(– but I have to admit: it is the less needed part of things. so, I am already quite happy as is.)

… so learned some bits. and made a step of progress. thx for that!

thx @pete31! ‘preguntando caminamos’… I am picking up crumbs of (scripting-)knowledge… . thx to you and others.
(for now, I´ll try to stay a little clear of smart rule… as there are too many other things to still figure out… :-})

No wonder. It’s (one of) the unloved step-child’s of Apple. Eg the language selection always reverts to AS. After closing/reopening the script editor.

It only inserts the TOC if there’s at least one line beginning with '# ’ (that’s a hash followed by a blank). Worked ok here, but you can of course leave out the condition and have the script always insert the TOC.
From your original post:

Admittedly, the script does not insert the TOC after the first top-level heading. But your example from above doesn’t even contain one. Only 2nd level ones. From an HTML point of view, that’s a bad structure, only h2 but no h1 elements.
Also, with this example, it would be quite difficult to insert the TOC after the first h1. Somewhere after the end of the file?

Anyway, I think you have a starting point now for your own explorations.

1 Like

hey @Pete31 – all understood. and indeed, I was ‘loose’ with the MD-structure, as a) it came from another use-context b) I was not thinking ‘technical’ enough (which is probably my issue with scripting).
– so, I am sure it works the way you describe. will test that later. and as you say, see where I can go w/ that backpack of things + hints you provided. thx for that!

I guess you mean @chrillek :wink:

1 Like

yep! :slight_smile:
(– thx for correcting my off-code slippery :wink: )