-
-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax Highlighting Themes for HTML #179
Conversation
background-color: #fdf6e3; | ||
border-style:solid; | ||
border-width:1px; | ||
border-color: #B0B0B0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these 3 lines can be merged as border: solid 1px #B0B0B0;
this looks pretty good; I'll be happy to merge it after you made the small change above you can also try to refactor the code as you wish; thanks a lot! |
I made the changes. I also reverted the background-color to the light gray that was used as the default before. |
I did not realize that these changes would be added to the pull request as well. I just refactored the code. Let me know if you want to pull these as well, or you will be able to selectively pull the user-visible changes first and pull these after you have had a chance to review. |
I can wait until you finish the work; at least I have not seen My original plan for #140 was to write the header into a separate file in the last step in |
\\makeatother | ||
## COMMIT: move .header.framed to a style file of its own so that it can be ## included or copied directly to the tex file | ||
.knit.sty <- system.file('misc', 'knitr.sty', package = 'knitr') | ||
.header.framed <- paste(readLines(.knit.sty), collapse = "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this really works, because the code will be run before knitr is installed, i.e. there is no knitr.sty
at that time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The alternative would be to move these lines directly inside the functions that use them. That way, they would be invoked only after knitr
is installed.
I like the idea of pulling the headers into a On a different note, I think it would be useful if you can add an option Let me know if you think this might be a good idea. If you think it is, and you agree with the two options, I can put together a patch addressing this and send you a pull request. If you think other ways of doing it might be better, do let me know so that we agree on a specification before further work. |
} | ||
if (!nzchar(h['highlight'])) { | ||
# header for Latex Syntax Highlighting | ||
.header.hi.tex = paste(theme_to_header_latex('edit-eclipse')$highlight, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is edit-eclipse
the default theme for LaTeX output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default that you had used previously. I remember reading a note of yours sometime, where you indicated that you found the colors of the default highlight theme too flashy for pdfs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think I mentioned it at some time, but I'm not actually using edit-eclipse
. The default theme has a light gray background, and the background of edit-eclipse
is white.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that event, I will create a default.latex.css
theme which has the gray
background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I do not see much gain of moving the two objects .header.framed
and .header.hi.tex
to two files respectively; I mean they are simply string constants and it is probably not worth it to read and write through extra files. At the end of the day, they will be concatenated in insert_header()
, and that will be the time to write the header into a separate file if opts_knit$get('self.contained') == TRUE
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, to some extent it is a style issue, since I don't prefer latex
and other markups contaminating my R code. Second, these are just defaults. So pulling them inside default files helps keep the code clean without cluttering them up with a lot of if.. else
statements. For instance, if we implement highlight.style
as an option, you can set it to default
and the headers would automatically correspond to them. Just my two cents :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, .header.hi.tex
can go to a file like default.css
. For .header.framed
, I'd rather leave it as is at the moment.
You can add For |
It might be a bad idea to use The use case for these options is that very often I generate multiple versions of my document, and I don't want to be tampering with the base document. I know, I can use |
I think |
I have made the changes to get (a) syntax highlighting in html and (b) allowing the header to be written to an external file using You will notice a few commits involving addition/removal of hooks for |
On a different note, I think there might be an opportunity to Let me know what you think. |
Oops... I made some changes to header.R and hooks.R, and this pull request cannot be automatically merged now. Is it possible for you to pull my changes and resolve the conflicts? Sorry for the trouble. Regarding S3 methods, you can experiment with it after this pull request or do it in another branch. Thanks! |
Done! You should be able to pull this now. Let me know if you still find some conflicts. |
It looks good now. I will take a look tonight. Thanks! |
Syntax Highlighting Themes for HTML
Is there an option to turn on these HTML themes with |
No. But you can do it by using |
currently themes only work for LaTeX and HTML output; if you want different themes for markdown-->html, you probably need to write your own css depending on which converter you use (sundown, pandoc, ...) I have seen your own tweak on twitter which looks very nice! |
I made some modifications to the file
themes.R
so that syntax highlighting themes work for html output as well. I tested it and it works. There is a lot of scope torefactor
the code here, but for now I focused on keeping the changes to a minimal.Let me know when you have a chance to review the code and pull in the changes.