Motivation-and-Behaviour / tidyMB

Templates, utilities, and style guides for use in Motivation and Behaviour Research Program
Other
0 stars 0 forks source link

[feature request] Remove header and continue quote arguments for read_manuscript() #9

Closed conig closed 4 years ago

conig commented 4 years ago

If sections extracted with read_manuscript() include headers, they cause the quote box to end early, and for the letter's numbering system to be invoked. This results in ugly formatting.

image

Perhaps arguments could be added in order to process the text further. This is currently what I'm using to get around the issue:

Change headers to bold

header_to_bold = function(string){

  while(grepl("#{1,}.*\\r",string)){

    target <- unlist(stringr::str_match(string, "#{1,}.*\\r"))[1]
    replacement <- gsub("#{1,}","**", target)
    replacement <- gsub("\\r","**\\\r", replacement)
    replacement <- gsub("\\*\\*\\s","**", replacement)

    string <- gsub(target, replacement, string)
  }

string

}

Continue quote after line break

string <- gsub("\\n","\\\n>",string) 

Which results in the following output:

get_revision = function(id){
   string <- tidyMB::read_manuscript(path, id)
   string <- papyr:::header_to_bold(string)
   string <- gsub("\\n","\\\n>",string)                       
   string
}

image

Is this the kind of thing you would want integrated into the read_manuscript() function? Happy to do a pull request. Let me know if you guys already have another solution implemented.

conig commented 4 years ago

I've implemented this, along with a few extras:

I've created a wrapper function get_revision() which:

  1. extracts text between html tags
  2. optionally evaluates inline code (you need to have all objects loaded through save.image/load)
  3. optionally continues quotes for multi-paragraph text
  4. optionally inserts page references

image