Inline codes are not highlighted after using "knit html" function in Rstudio - html

I wrote an .Rmd file with some inline codes quoted by "`", and I used the knit html function in Rstudio to convert the .Rmd file to .html. However, the inline codes were not highlighted as on stackoverflow, and I took a look at the source codes of the .html file and found that the setting was like
tt, code, pre {
font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
}
And I tried altering this block:
tt, code, pre {
font-family: 'DejaVu Sans Mono', 'Droid Sans Mono', 'Lucida Console', Consolas, Monaco, monospace;
background-color: #F8F8F8;
}
And it worked.
However, I do not want to do such work every time after I knit the .Rmd file to .html. I have read the help files of knit2html and markdownHTMLOptions in R but found no solution. Is there any solution to this issue?

With the latest version of the markdown package on CRAN, you can use the header argument to add additional CSS code to the HTML output, e.g.
library(knitr)
knit2html(...,
header = c('<style type="text/css">', 'code{background-color: #F8F8F8;}', '</style>'))
Or just set this as a global option in your ~/.Rprofile:
options(markdown.HTML.header = c('<style type="text/css">', 'code{background-color: #F8F8F8;}', '</style>'))
And the markdown package will use it every time when you simply run knit2html() without explicitly specifying the header argument.
With RStudio, it is a little trickier. See the documentation Customizing Markdown Rendering.

Related

"downloadable font: rejected by sanitizer" in Firefox when font hosted on the web

I am trying to use a custom font (format woff2). The font works well in Chrome (whether on local files or when the html and font files are hosted on the web), but it fails to load on Firefox when the html page and font are hosted on the web with the following error:
downloadable font: rejected by sanitizer (font-family: "My Sans Regular" style:normal weight:400 stretch:100 src index:0) source: https://host/resources/my_sans_reg_web.woff2
Here is how the font is specified in the page:
#font-face {
font-family: 'My Sans Regular';
src: url('resources/my_sans_reg_web.woff2') format('woff2');
}
body, span, button, input, textarea, form, mark, table, th, td, p, h4, h5, a {
font-family: 'My Sans Regular';
}
The size of the font file is 41kb, so it cannot be a memory issue (as suggested here https://support.mozilla.org/en-US/questions/913498 ).
I researched the issue on the web and on this site, but I could not find a solution or an issue that matched exactly mine.
I am using Firefox version 91.13.0esr.

Custom font in angular 10 project is loaded in network, styles are applied but is not rendered on text

I have installed the custom font roboto in a new Angular project.
In the network tab the status is 200 for the roboto variants used in styles (regular and bold)
In the component I have a custom class with font-family: Roboto that is correctly applied to the p element.
I have added the roboto-fontface.css from the npm package to angular.json's styles array and is accessible from the dev tools sources tabs. I have defined in roboto-fontface.css a custom class that is applied to an element, so it load properly.
However, the roboto font is not applied to the p element.
Put your font files in /assets/fonts/
And then in scss define #font-face and use acordingly.
For example:
#font-face {
font-family: "Source Serif Pro";
src: url("^assets/fonts/source-serif-pro/SourceSerifPro-Regular.ttf") format("ttf");
font-weight: 400;
}
h2 {
font-family: 'Source Serif Pro', sans-serif;
}
Not need to install or put in angular.json

How should I add support for obscure alphabets to my website?

The Problem
I've made a website for myself, using the Express framework for NodeJS, and it works pretty much as I'd hoped it would.
One remaining irritation is how best to provide support for the more obscure scripts and alphabets the world has to offer.
At present, I'm using a version of the Computer Modern font, using these files specifically, which I import via CSS in the following code:
#font-face {
font-family: computerModern;
src: url("fonts/cmunrm.ttf");
}
#font-face {
font-family: computerModern;
src: url("fonts/cmunti.ttf");
font-style: italic;
}
#font-face {
font-family: computerModern;
src: url("fonts/cmunbx.ttf");
font-weight: bold;
}
#font-face {
font-family: computerModern;
src: url("fonts/cmunbi.ttf");
font-weight: bold;
font-style: italic;
}
...
body {
font-family: computerModern, serif;
padding-left: 20px;
padding-right: 20px;
}
This approach has worked quite well so far - up to a point. The Latin alphabet is printed beautifully, as are the Greek and Cyrillic alphabets. Arab text also looks pretty, although, looking through the character lists of the .ttf files, my browser must just be pulling out its default Arabic font; as luck would have it, the default Arabic font complements Computer Modern rather well. But I begin to run into more serious difficulties when I want to print, for example, people's names in their native Georgian characters, e.g. სალომე ზურაბიშვილი = Salome Zourabichvili. The correct characters are printed, but my browser's default Georgian font is hideous when side by side with Computer Modern.
Potential Solutions
How should I add support for the Georgian alphabet, and other obscure scripts, so that characters are printed in a font which dovetails with aesthetic of the rest of my website? I can think of four potential solutions, two of which I'd know how to implement but are unsatisfactory, and two of which I don't know how to implement.
Known but Unsatisfactory Solutions
Replacing the current .ttf files with files which cover all the desired characters. Unsatisfactory because I can't find such files.
Creating a new HTML tag of the span class for each obscure alphabet, any wrapping any text of that alphabet in such a tag. Unsatisfactory because the website has thousand of pages, with new ones being added all the time, and don't trust myself, let alone anyone else, to remember to use the appropriate tags.
Solutions I Don't Know How to Implement
Splicing .tff files, i.e. copying characters from a.ttf to b.ttf.
Adding characters from multiple .ttf files to one CSS font-family, and with the same font-style, font-weight, etc.
Why dont you target the html lang and load different fonts per language if needed?
Example:
html[lang=ja]>body {
font-family: 'Yu Gothic', Arial, Helvetica, sans-serif;
}
html[lang=ko]>body {
font-family: 'Noto Sans KR', Arial, Helvetica, sans-serif;
}
html[lang=zh]>body {
font-family: 'Noto Serif SC', Courier, Georgia, serif;
}
Regards

Font is loading as Bold and not Un-Bolding

My font is auto loading as bold and won't behave to the 'normal' property. I want it to be standard and then bold it when i need it. In addition, it is not changing to normal at any other part of the document.
Can someone help me?
#font-face {
font-family: Avenir;
src: url('type/AvenirNext.ttc');
font-weight: normal;
Where did you get your font file? Are you sure that it can be used for multiple weights? From this git repository it seems like there are different files for different weights.
If you think you can use your file for multiple weights, you could try using a range of weights like font-weight: 400 700; as described in these docs.
Those docs also recommend specifying a font format src: url('type/AvenirNext.ttc') format("truetype");.
If none of this works, are you able to post a link demonstrating the problem?
.fonts {
font-family: Avenir;
src: url('type/AvenirNext.ttc');
font-weight: normal;
font-size: 30px;
}
<div class="fonts">This is text</div>
Whatever you have to take a class name that is conflicting to properties, Now you have to see the above code I have to change the class name it's working.
Try this
#font-face {
font-family: Avenir;
src: url('type/AvenirNext.ttc');
font-weight: unset!important;

How do I used a Google web font as a SUBSTITUTE font?

I am trying to use a Google web font as a substitute font. But instead of being a substitute font, it is acting as a primary font.
In my , I have it linked to the font:
<link href='http://fonts.googleapis.com/css?family=Balthazar' rel='stylesheet' type='text/css'>
In my CSS, I have variations of the Copperplate font and I know it works on my PC and I have some of them installed. This part is at the beginning of my CSS:
.class{
font-size: 24pt;
font-family: Copperplate Gothic Bold, Copperplate Gothic Light, Copperplate, Balthazar;
}
But even though Balthazar is the last font, it is coming up as the first. Ho wo I fix ths?
font-family degradation appears to work just fine with Google font in all three of their import scenarios (#import, <link>, or JavaScript).
See this example: http://jsfiddle.net/awRQm/
The most likely cause is that it really is falling back to Balthazar.
For multi-word font names, it's best to wrap them in single quotes like so:
.class{ font-size: 24pt; font-family: 'Copperplate Gothic Bold', 'Copperplate Gothic Light', Copperplate, Balthazar; }
According to the CSS 2.1 spec:
"if a sequence of identifiers is given as a font family name, the
computed value is the name converted to a string by joining all the
identifiers in the sequence by single spaces"
Fonts that have spaces in the name must be put in quotations in order to be read properly by css, this also goes for google web fonts, just to be on the safe side.
Example: font:family: "Copperplate Gothic Bold", "Copperplate Gothic Light", Copperplate, "Balthazar";