Skip to content

Commit 1871e33

Browse files
committed
Improvement: Showing Markdown as HTML
1 parent 808b4bf commit 1871e33

File tree

7 files changed

+79
-23
lines changed

7 files changed

+79
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.vscode/

front-end/package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

front-end/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
},
1414
"private": true,
1515
"dependencies": {
16-
"node-forge": ">=1.3.0",
17-
"shelljs": ">=0.8.5",
1816
"@angular/common": "^12.2.16",
1917
"@angular/core": "^12.2.16",
2018
"@angular/forms": "^12.2.16",
@@ -28,13 +26,14 @@
2826
"cordova-browser": "^6.0.0",
2927
"core-js": "^2.5.4",
3028
"firebase": "^9.8.0",
29+
"marked": "^4.0.15",
30+
"node-forge": ">=1.3.0",
3131
"rxjs": "^6.6.0",
32+
"shelljs": ">=0.8.5",
3233
"tslib": "^2.0.0",
3334
"zone.js": "~0.11.4"
3435
},
3536
"devDependencies": {
36-
"node-forge": ">=1.3.0",
37-
"shelljs": ">=0.8.5",
3837
"@angular-devkit/architect": "~0.1202.17",
3938
"@angular-devkit/build-angular": "^12.2.17",
4039
"@angular-devkit/core": "~12.2.17",
@@ -47,6 +46,7 @@
4746
"@ionic/lab": "^3.2.11",
4847
"@types/jasmine": "~3.6.0",
4948
"@types/jasminewd2": "~2.0.3",
49+
"@types/marked": "^4.0.3",
5050
"@types/node": "^12.11.1",
5151
"codelyzer": "^6.0.0",
5252
"cordova-plugin-device": "^2.0.2",
@@ -62,7 +62,9 @@
6262
"karma-coverage-istanbul-reporter": "~3.0.2",
6363
"karma-jasmine": "~4.0.0",
6464
"karma-jasmine-html-reporter": "^1.5.0",
65+
"node-forge": ">=1.3.0",
6566
"protractor": "~7.0.0",
67+
"shelljs": ">=0.8.5",
6668
"ts-node": "^8.0.3",
6769
"tslint": "~6.1.0",
6870
"typescript": "~4.3.5"

front-end/src/app/pages/cadastro-vaga/cadastro-vaga.page.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<ion-header>
22
<ion-toolbar>
3-
<ion-menu-button></ion-menu-button>
3+
<ion-buttons slot="start">
4+
<ion-back-button></ion-back-button>
5+
<ion-menu-button></ion-menu-button>
6+
7+
</ion-buttons>
48
<ion-title>
59
Cadastro de vaga
610
</ion-title>
@@ -15,12 +19,8 @@
1519
</ion-item>
1620
<ion-item>
1721
<ion-label position="stacked">Descrição</ion-label>
18-
<ion-textarea
19-
[ngModel]="vaga?.body"
20-
rows="15"
21-
cols="20"
22-
placeholder="Digite da vaga"
23-
></ion-textarea>
22+
<div [innerHTML]="getContent(vaga?.body)"></div>
23+
2424
</ion-item>
2525
<ion-item>
2626
<ion-label position="floating">Labels</ion-label>
Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
1-
import {VagaService} from 'src/app/service/vaga.service';
2-
import {Router, ActivatedRoute} from '@angular/router';
3-
import {Component, OnInit} from '@angular/core';
4-
import {Vaga} from 'src/app/model/vaga.model';
1+
import { VagaService } from "src/app/service/vaga.service";
2+
import { Router, ActivatedRoute } from "@angular/router";
3+
import { Component, OnInit } from "@angular/core";
4+
import { Vaga } from "src/app/model/vaga.model";
5+
import { DomSanitizer } from "@angular/platform-browser";
6+
import { marked } from "marked";
57

68
@Component({
7-
selector: 'app-cadastro-vaga',
8-
templateUrl: './cadastro-vaga.page.html',
9-
styleUrls: ['./cadastro-vaga.page.scss']
9+
selector: "app-cadastro-vaga",
10+
templateUrl: "./cadastro-vaga.page.html",
11+
styleUrls: ["./cadastro-vaga.page.scss"],
1012
})
1113
export class CadastroVagaPage implements OnInit {
1214
constructor(
1315
private route: ActivatedRoute,
14-
private vagaService: VagaService
16+
private vagaService: VagaService,
17+
private sanitizer: DomSanitizer
1518
) {}
1619

20+
private renderer = new marked.Renderer();
21+
private defaultOptions: marked.MarkedOptions = {};
22+
1723
vaga: Vaga;
1824
ngOnInit() {
25+
this.applyDefaultOptions();
1926
this.vagaService
20-
.getVagaById(this.route.snapshot.params['id'])
21-
.subscribe(result => {
27+
.getVagaById(this.route.snapshot.params["id"])
28+
.subscribe((result) => {
2229
this.vaga = result;
2330
});
2431
}
2532

33+
getContent(content: string) {
34+
const html = content ? marked(content, this.defaultOptions) : "";
35+
return this.sanitizer.bypassSecurityTrustHtml(html);
36+
}
37+
2638
getLabels(labels) {
2739
if (labels) {
28-
let labelMap = labels.map(a => a.name);
40+
let labelMap = labels.map((a) => a.name);
2941
if (labelMap.length > 0) {
30-
return labelMap.reduce(a => a + ', ');
42+
return labelMap.reduce((a) => a + ", ");
3143
}
3244
}
3345
}
46+
47+
private applyDefaultOptions() {
48+
// Native links will open in new tab
49+
this.renderer.link = function (href, title, text) {
50+
title = title || href;
51+
return `<a target="_blank" rel="noopener" href="${href}" title="${title}">${text}</a>`;
52+
};
53+
this.defaultOptions.renderer = this.renderer;
54+
}
3455
}

front-end/src/app/pages/vagas/vagas.page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Vaga} from './../../model/vaga.model';
22
import {Component, OnInit} from '@angular/core';
33
import {VagaService} from 'src/app/service/vaga.service';
44
import {Router} from '@angular/router';
5+
import { DomSanitizer } from '@angular/platform-browser';
56

67
@Component({
78
selector: 'app-vagas',

front-end/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compileOnSave": false,
33
"compilerOptions": {
4+
"allowJs": true,
45
"baseUrl": "./",
56
"downlevelIteration": true,
67
"outDir": "./dist/out-tsc",

0 commit comments

Comments
 (0)