I want to expand the nice answer by @JBGruber:
This code will work for html and word as output:
```{css, echo=FALSE}
span.comment-start{
background: #e0f3db;
}
span.comment-end{
background: #e0f3db;
}
span.comment-start::after{
content: " (" attr(author) ", " attr(date) ") [";
}
span.comment-end::before{
content: "]"
}
span.comment-text{
background: #fdbb84;
}
```
```{r, echo=FALSE}
commentN <- 0
cmt <- function(txt, cm, author, date = "2021-01-01", comN = commentN){
cmt_str <- paste0('<span class="comment-text">[',cm,']{.comment-start id="', comN, '" author="', author, '" date="', date, '"}', txt, '[]{.comment-end id="',commentN,'"}</span>')
assign("commentN", commentN + 1, envir = .GlobalEnv)
return(cmt_str)
}
```
and you can add comments in your text by calling
`r cmt("Text to be commented", "The comment itself", "myName", "Date")`