Ver código fonte

Application advanced printing/formatting

Text answers now escape HTML and print newlines and tabs. Empty answers have a space holder. And links answers (arrays) will be printed as links.
Ecconia 7 anos atrás
pai
commit
0b354e4552
1 arquivos alterados com 25 adições e 2 exclusões
  1. 25 2
      src/views/Application.vue

+ 25 - 2
src/views/Application.vue

@@ -3,9 +3,15 @@
 		<h1>Application by {{ appdata.username }}</h1>
 		<span v-if="error !== ''">{{ error }}</span>
 		<div class="appdata" v-else>
-			<div class="pair" v-for="(value, key) in appdata.fields" :key="key">
+			<div class="pair _124ig23u5f235u" v-for="(value, key) in appdata.fields" :key="key">
 				<h4>{{ key }}</h4>
-				<p>{{ value }}</p>
+				<p v-if="Array.isArray(value)">
+					<span v-for="link in value">
+					<span>- </span><a :href="link">{{ link }}</a><br>
+					</span>
+				</p>
+				<p v-else-if="value === ''"> -/- </p>
+				<p v-else v-html="'' + escape(value) + ''"></p>
 			</div>
 		</div>
 	</div>
@@ -29,10 +35,27 @@
 			})
 		},
 		methods: {
+			escape(html) {
+				html = html.replace(/</g, '&lt;')
+				html = html.replace(/>/g, '&gt;')
+
+				html = html.replace(/\n/g, '<br>')
+				html = html.replace(/(\t+)/g, '<pre>$1</pre>')
+
+				return html
+			}
 		},
 	}
 </script>
 
+<style>
+	/* TODO: Convert to scoped... */
+	._124ig23u5f235u pre {
+		margin: 0em;
+		display: inline;
+	}
+</style>
+
 <style scoped>
 	.appdata {
 		/width: 63em;