Highlighjs для динамического выделения синтаксиса в Angular 8 - PullRequest
0 голосов
/ 19 июня 2019

Я пытаюсь сделать подсветку синтаксиса с помощью highligh-js

файл details.component.html:

 <pre highlight-js> <!–– this block gets highlihgted -->
    <code>
/* tslint:disable */
import numpy as np
def printing():
    hello_srt = "hello"
    for i in range():
        print(i)
    return hello_str
printing()<br>
    
      
<! –– этот блок не выделен ->

details.component.html:

@Component({
  selector: 'app-details',
  templateUrl: './details.component.html',
  encapsulation: ViewEncapsulation.None,
  styleUrls: ['./details.component.css']
})



export class InterviewDetailsComponent implements OnInit, AfterViewChecked, AfterViewInit {
  @ViewChild('dataContainer', {static: true}) dataContainer: ElementRef;
  @ViewChild('description-content', {static: false}) questionContainer: ElementRef;
  companyDetails: CompanyDetails;  
  question: string;


  // dataService: DataService;

  constructor(private dataService: DataService,
              private highlightService: HighlightService,
              private interViewSharedService: InterviewSharedService,
              private dynamicScriptLoaderService: DynamicScriptLoaderService) {
    this.question = 'Loading';
    this.getPage(this.interViewSharedService.interviewId);

  }



  getPage(page: number) {
    // this 
    this.dataService.getInterviewPage(page)
      .subscribe((response: CompanyInterview) => {
        // response coming form service 
        // service pulls data from dabase server
        this.companyDetails = response;
        this.rounds = [];
        this.question = this.companyDetails.rounds[0];
      });
  }

  ngOnInit(): void {
  }

}

значение переменной this.question, поступающей из ответа, который является тем же блоком, что и в html:

<pre highlight-js> <!–– this block gets highlihgted -->
        <code>
    /* tslint:disable */<br>
    import numpy as np<br>
    def printing():<br>
        hello_srt = "hello"<br>
        for i in range():<br>
            print(i)<br>
        return hello_str<br>
    printing()<br>
        
          
  • Но эта строка из базы данных не подсвечивается:

enter image description here

  • Я хочу, чтобы html-контент динамически вставлялся в тег <div>, выделялись только теги <code> этого динамического html, а не весь тег <div>
...