如何在rmarkdown文档中的htmltools中使用带有特殊字符的标签?

时间:2018-03-29 16:33:57

标签: r r-markdown htmltools

在rmarkdown文档中,如何在带有htmltools包的标记内使用HTML特殊字符?

如果我们在rmarkdown文档的r块中写这样的话

htmltools::tags$th("μ")

我们得到:

<th>&amp;mu;</th>

而不是

<th>&mu;</th>

2 个答案:

答案 0 :(得分:0)

你能解决这个问题吗?

gsub("amp", "", htmltools::tags$th("&mu;"))
<th>&mu;</th>

答案 1 :(得分:0)

const Login =(props:any) =>{ const [state, setState] = useState({ Email:'', Password:'' }); const inputOnChange = (e:any) => { setState({ ...state, [e.target.name]: e.target.value }) }; useEffect(()=>{ const token = localStorage.getItem('Token'); if(token !== null) { props.authTokenCheck() } // eslint-disable-next-line react-hooks/exhaustive-deps },[localStorage.getItem('Token')]) ; const loginButtonEvent = (e:any) => { props.authLogin(state.Email, state.Password) }; return( <div> {props.auth.isAuthenticated? <div> <h1>I am authenticated</h1> <h2>{`${props.auth.isAuthenticated}`}</h2> </div>: <div> <div> {props.auth.loading? <div><h1>Loading</h1></div> : <div> <input placeholder={'Email Address'} name={'Email'} onChange={(e)=>{inputOnChange(e)}} type="text"/> <input placeholder={'Password'} name={'Password'} onChange={(e)=>{inputOnChange(e)}} type="password"/> <button onClick={(e)=>{loginButtonEvent(e)}}>Login</button> </div> } </div> </div>} </div> }; const mapStateToProps = (state:any) =>({ auth: state.auth }); const mapDispatchToProps = (dispatch:any) => { return { // dispatching actions returned by action creators authLogin: (email:string,password:string) => dispatch(authLogin(email,password)), authTokenCheck: () => dispatch(authTokenCheck()), } }; export default connect(mapStateToProps, mapDispatchToProps)(Login) 软件包为此提供了一个功能htmltools

HTML

结果为:

require(htmltools)
require(magrittr)

"&mu;" %>% HTML %>% (tags$th) %>% as.character %>% cat