MCPcopy Create free account
hub / github.com/codemistic/Web-Development / heading2

Function heading2

jsonRenderer2/src/App.js:42–88  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

40 },[data]);
41
42 const heading2 = (content) =>{
43 if (content){
44 return (<h2>{content}</h2>)
45 }
46}
47
48function NewlineText(props) {
49 const text = props.text;
50 const newText = text.split('\n').map(str => <p className='content'>{str}</p>);
51 return newText;
52}
53
54const paragraph = (content)=>{
55 if (content){
56 return (<NewlineText text={content} ></NewlineText>)
57 }
58}
59
60//function to check base64 encoding
61const isBase64 = (str) => {
62 if (str ==='' || str.trim() ===''){ return false; }
63 try {
64 return btoa(atob(str)) === str;
65 } catch (err) {
66 return false;
67 }
68}
69
70//function to decode base64
71const Base64ToString = (encode) => {
72 let buff = new Buffer(encode, 'base64');
73 let decoded = buff.toString('ascii');
74 return decoded;
75}
76
77//function to render encoded image file and https image
78const renderBase64Image = (source, alt_text, height, width) => {
79 if(source.startsWith("https") || source.startsWith("http")){
80 return (
81 <img src={source} alt={alt_text || "image"} className="list-img" height={height || "400px"} width={width || "650px"}/>
82 );
83 }
84 else if(isBase64(source)===true){
85 const decoded = Base64ToString(source);
86 const s = `data:image/png;base64,${source}`;
87 return(
88 <img src={s} alt={alt_text || "image"} className="list-img" height={height || "400px"} width={width || "650px"}/>
89 );
90 }
91}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected