# Custom Processor Arguments without setting its state

#### connor

26 Mar, 2020 03:36 AM

As you mention in the documentation, we can set per-document custom (pre)processor settings as a JSON array to pass additional arguments to the processor. A la:

Custom Processor: [true, "-o", "html"]


Is it possible to set parameters to be passed to the processor without forcing the processor to be on or off in the document, and then they are just ignored if the custom processor is off? For example, something like

Custom Processor: [NULL, "-o", "html"]


I like to be able to enable and disable the custom processor with the indicator button in the Marked pane, but when I am passing arguments in the document, the state is not affected by clicking the indicator, and I can only enable or disable the processor by editing the document.

Obviously this isn't a huge dealbreaker if it isn't possible. It would just mean I'd have to write a more complex processor script to dig into the document content manually, or just not have the clicky button. But it could be a nice thing to have.

1. Support Staff Posted by Brett on 26 Mar, 2020 12:51 PM

The way I have it implemented at this time will not allow a JSON string
to be anything other than true or false in the first argument. I can see
the utility of what you're asking, so I'll take a look at modifying that
in the future.

No option for the immediate present, though.

-Brett

2. Posted by connor on 26 Mar, 2020 02:28 PM

No worries! It's definitely easy to work around with a more intelligent
processor script. Thanks!

3. Posted by connor on 30 Mar, 2020 03:43 PM

So, either I'm a little bit insane, you snuck in an app update without me noticing, or there's a ghost in my computer, but Marked is now exhibiting almost this behavior? Except in a way that I think is a bug. Example document:

Custom Preprocessor: [true, "pdf", "true"]

# A lovely test document

Hello there!


If I open this document in Marked, the Custom Preprocessor is off by default, and the toggle button remains clickable. If I toggle the Custom Preprocessor on, it passes along the JSON arguments, but the first argument of true or false appears to be ignored.

As nice as it is that my prayers have been answered by a bug, I don't think this is the optimal behavior.

Thanks!

4. Support Staff Posted by Brett on 30 Mar, 2020 04:22 PM

I'll be honest, I think you're the first person in Marked's history to even explore the JSON option here, so it hasn't received much attention. I'll look into it.

- Brett

5. Posted by connor on 30 Mar, 2020 05:04 PM

Ha! Should I be writing a more intelligent script in something other than bash? Probably, but I'm still a baby script writer so the JSON arguments make for a good baby step to parsing YAML headers myself in python. Someday I'll get there!

6. Support Staff Posted by Brett on 30 Mar, 2020 05:26 PM

There are lots of ways you can branch logic using variables and content parsing, whether in yaml blocks or otherwise. Just depends on your scripting language of choice. Give me an idea what you're trying to do, I might have suggestions.

That said, I do want to improve the JSON arguments feature if I'm going to offer it, no point implementing something half-baked.

- Brett

7. Posted by connor on 30 Mar, 2020 07:24 PM

I am yet another devoted fan of pandoc, primarily via R Markdown documents. Most of the time I'm just writing in RStudio, but if what I'm writing is all words and no code, RStudio is more than I need, but I still want to use R to compile the documents via pandoc. What I probably should do (which I only now thought about doing, so thanks for the prompting) is just write an executable R script and have THAT be the preprocessor rather than trying to reinvent the wheel with my own bash script…

In essence, I am trying to do an end around adding my own items to the Export drawer via a Preprocessor. I don't feel strongly about setting a custom processor to preview the exact output in Marked, both because all I really care about is the text content rather than the formatting, and because more often than not I want a LaTeX PDF or a Word document rather than HTML, and I prefer to generate those documents cleanly via pandoc rather than attached to a Marked template routed through HTML.

8. Posted by connor on 31 Mar, 2020 12:27 AM

Wow I just wrote an R script directly to do this and it is much better. Putting it here for posterity just in case someone else stumbles upon this thread, but I guess what I would underscore as my takeaway from this exercise is a feature request to be able to customize the contents of the Export Drawer. This really belongs there, and the preprocessor is just a workaround.

The R processor, if it's of interest:

#!/usr/bin/env Rscript
# A custom preprocessor for Marked 2 to call rmarkdown::render() on the source document,
# then cancel the processor and have Marked resume processing.

## First get the environment set up so we can call render()
# Work around a bug in render() that doesn't remove .tex file when the working directory
# is not where the file is
setwd(Sys.getenv("MARKED_ORIGIN"))

# Add pandoc and LaTeX to PATH so render() can find them.
# Note these hardcoded paths might need to be changed for different systems
Sys.setenv(RSTUDIO_PANDOC = "/Applications/RStudio.app/Contents/MacOS/pandoc/")
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "/Library/TeX/texbin/", sep = ":"))

rmarkdown::render(Sys.getenv("MARKED_PATH"), quiet = TRUE)

cat("NOCUSTOM")  # to return to the main processor


Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

### »

#### Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

# Keyboard shortcuts

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 03 Apr, 2020 09:11 PM Marked 2 crashes as soon as I try to open a file 03 Apr, 2020 03:49 PM MathJax processing 31 Mar, 2020 12:27 AM Custom Processor Arguments without setting its state 30 Mar, 2020 04:20 PM Passing nonquoted boolean JSON argument to Preprocessor causes Marked to crash 25 Mar, 2020 08:19 PM Symlink to Custom Preprocessor Not Working

## Recent Articles

 Fenced code blocks inside indented code blocks Using JavaScript in Marked Custom CSS: Writing custom CSS for Marked License code has already been utilized Highlight sentences longer than a certain number of words