LineOfCode.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!--
  2. Container which display a single line of code of a file.
  3. -->
  4. <template>
  5. <div :class="{'first-line' : isFirst, 'last-line' : isLast, 'visible' : visible}" :style="{background : color}"
  6. class="line-wrap">
  7. <pre :id="text" ref="lineRef" :class="{ 'match-line' : color !== '#ECECEC' }" class="java">{{ lineNumber }} {{
  8. text
  9. }}</pre>
  10. </div>
  11. </template>
  12. <script>
  13. import {defineComponent, onUpdated, ref} from "vue";
  14. import hljs from 'highlight.js';
  15. export default defineComponent({
  16. name: "LineOfCode",
  17. props: {
  18. /**
  19. * Indicates whether the line is shown on screen. Used for highlighting on demand.
  20. */
  21. visible: {
  22. type: Boolean,
  23. required: true
  24. },
  25. text: {
  26. type: String,
  27. required: true
  28. },
  29. lineNumber: {
  30. type: Number,
  31. required: true
  32. },
  33. color: {
  34. required: true
  35. },
  36. fileIndex: {
  37. type: Number,
  38. },
  39. isFirst: {
  40. type: Boolean,
  41. },
  42. isLast: {
  43. type: Boolean,
  44. }
  45. },
  46. setup(props) {
  47. let highlighted = false
  48. let lineRef = ref(null)
  49. //Trigger highlighting when code panel is collapsed.
  50. onUpdated(() => {
  51. if (props.visible && !highlighted) {
  52. hljs.highlightElement(lineRef.value)
  53. highlighted = true
  54. }
  55. })
  56. return {
  57. lineRef
  58. }
  59. }
  60. })
  61. </script>
  62. <style scoped>
  63. pre {
  64. /* In hljs pre tag is used. We need this style to override attributes in the styles of higlightjs to show code more
  65. compact */
  66. margin: 0;
  67. padding: 0;
  68. float: left;
  69. }
  70. pre code.hljs {
  71. padding: 0 !important;
  72. }
  73. code.hljs {
  74. padding: 0 !important;
  75. }
  76. .hljs {
  77. background: transparent !important;
  78. font-family: "JetBrains Mono NL", serif !important;
  79. font-weight: bold; font-size: x-small !important;
  80. }
  81. .first-line {
  82. margin-top: 2%;
  83. }
  84. .last-line {
  85. margin-bottom: 2%;
  86. box-shadow: #777777 0 3px 3px;
  87. }
  88. .match-line {
  89. }
  90. .line-wrap {
  91. width: 200%;
  92. }
  93. </style>