4747 padding : 10px ;
4848 overflow-wrap : break-word;
4949 }
50+ # loading {
51+ display : none;
52+ margin-top : 20px ;
53+ }
54+ # result {
55+ display : none;
56+ }
57+ iframe {
58+ width : 100% ;
59+ height : 500px ;
60+ border : 1px solid # ccc ;
61+ }
5062 @media (min-width : 768px ) {
5163 # url-input {
5264 width : 70% ;
6577< body >
6678 < h1 > Jina Reader</ h1 >
6779 < p > An interface for the < a href ="https://jina.ai/reader/ "> Jina Reader API</ a > .</ p >
68- < input type ="text " id ="url-input " placeholder ="Enter URL ">
69- < button id ="submit-btn "> Submit</ button >
70- < textarea id ="markdown-raw " readonly > </ textarea >
71- < button id ="copy-btn "> Copy to clipboard</ button >
72- < div id ="markdown-rendered "> </ div >
80+ < form id ="url-form ">
81+ < input type ="text " id ="url-input " placeholder ="Enter URL " required >
82+ < button type ="submit " id ="submit-btn "> Submit</ button >
83+ </ form >
84+ < div id ="loading "> Loading...</ div >
85+ < div id ="result ">
86+ < textarea id ="markdown-raw " readonly > </ textarea >
87+ < button id ="copy-btn "> Copy to clipboard</ button >
88+ < iframe id ="markdown-rendered " sandbox > </ iframe >
89+ </ div >
7390
7491 < script >
92+ const urlForm = document . getElementById ( 'url-form' ) ;
7593 const urlInput = document . getElementById ( 'url-input' ) ;
76- const submitBtn = document . getElementById ( 'submit-btn' ) ;
94+ const loading = document . getElementById ( 'loading' ) ;
95+ const result = document . getElementById ( 'result' ) ;
7796 const markdownRaw = document . getElementById ( 'markdown-raw' ) ;
7897 const copyBtn = document . getElementById ( 'copy-btn' ) ;
7998 const markdownRendered = document . getElementById ( 'markdown-rendered' ) ;
8099
81- submitBtn . addEventListener ( 'click' , async ( ) => {
100+ urlForm . addEventListener ( 'submit' , async ( e ) => {
101+ e . preventDefault ( ) ;
82102 const url = urlInput . value ;
83103 if ( ! url ) return ;
84104
105+ loading . style . display = 'block' ;
106+ result . style . display = 'none' ;
107+
85108 try {
86109 const response = await fetch ( `https://r.jina.ai/${ url } ` ) ;
87110 const markdown = await response . text ( ) ;
88111 markdownRaw . value = markdown ;
89- markdownRendered . innerHTML = marked . parse ( markdown ) ;
112+ const htmlContent = `
113+ <html>
114+ <head>
115+ <style>
116+ body { font-family: Helvetica, sans-serif; line-height: 1.6; color: #333; }
117+ img { max-width: 100%; height: auto; }
118+ </style>
119+ </head>
120+ <body>
121+ ${ marked . parse ( markdown ) }
122+ </body>
123+ </html>
124+ ` ;
125+ markdownRendered . srcdoc = htmlContent ;
126+ result . style . display = 'block' ;
90127 } catch ( error ) {
91128 console . error ( 'Error fetching markdown:' , error ) ;
92129 markdownRaw . value = 'Error fetching markdown. Please try again.' ;
93- markdownRendered . innerHTML = '' ;
130+ markdownRendered . srcdoc = '<p>Error fetching markdown. Please try again.</p>' ;
131+ result . style . display = 'block' ;
132+ } finally {
133+ loading . style . display = 'none' ;
94134 }
95135 } ) ;
96136
@@ -107,4 +147,4 @@ <h1>Jina Reader</h1>
107147 } ) ;
108148 </ script >
109149</ body >
110- </ html >
150+ </ html >
0 commit comments