博客园实现代码片高亮及行号显示

由于博客园默认代码片实在太丑,希望实现sublime风格的代码显示,通过添加css代码实现,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
/*Markdown*/
/*
Monokai Sublime style. Derived from Monokai by noformnocontent http://nn.mit-license.org/
*/

/*.cnblogs-markdown pre {
overflow: auto;
}

.cnblogs-markdown table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
}

.cnblogs-markdown pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}

.cnblogs-markdown pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}*/

/*以下代码可增加横向滑动条,防止行号错位*/
#cnblogs_post_body {
margin: 20px 0;
}

.cnblogs-markdown {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
color: #333;
overflow: hidden;
font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
font-size: 16px;
line-height: 1.6;
word-wrap: break-word;
}

.cnblogs-markdown a {
background: transparent;
}

.cnblogs-markdown a:active,
.cnblogs-markdown a:hover {
outline: 0;
}

.cnblogs-markdown strong {
font-weight: bold;
}

.cnblogs-markdown h1 {
font-size: 2em;
margin: 0.67em 0;
}

.cnblogs-markdown img {
border: 0;
}

.cnblogs-markdown hr {
box-sizing: content-box;
height: 0;
}

.cnblogs-markdown pre {
overflow: auto;
}

.cnblogs-markdown code,
.cnblogs-markdown kbd,
.cnblogs-markdown pre {
font-family: monospace, monospace;
font-size: 1em;
}

.cnblogs-markdown input {
color: inherit;
font: inherit;
margin: 0;
}

.cnblogs-markdown html input[disabled] {
cursor: default;
}

.cnblogs-markdown input {
line-height: normal;
}

.cnblogs-markdown input[type="checkbox"] {
box-sizing: border-box;
padding: 0;
}

.cnblogs-markdown table {
border-collapse: collapse;
border-spacing: 0;
}

.cnblogs-markdown td,
.cnblogs-markdown th {
padding: 0;
}

.cnblogs-markdown * {
box-sizing: border-box;
}

.cnblogs-markdown input {
font: 13px/1.4 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
}

.cnblogs-markdown a {
color: #4183c4;
text-decoration: none;
}

.cnblogs-markdown a:hover,
.cnblogs-markdown a:active {
text-decoration: underline;
}

.cnblogs-markdown hr {
height: 0;
margin: 15px 0;
overflow: hidden;
background: transparent;
border: 0;
border-bottom: 1px solid #ddd;
}

.cnblogs-markdown hr:before {
display: table;
content: "";
}

.cnblogs-markdown hr:after {
display: table;
clear: both;
content: "";
}

.cnblogs-markdown h1,
.cnblogs-markdown h2,
.cnblogs-markdown h3,
.cnblogs-markdown h4,
.cnblogs-markdown h5,
.cnblogs-markdown h6 {
margin-top: 15px;
margin-bottom: 10px;
line-height: 1.1;
}

.cnblogs-markdown blockquote {
margin: 0;
}

.cnblogs-markdown ul,
.cnblogs-markdown ol {
padding: 0;
margin-top: 0;
margin-bottom: 0;
}

.cnblogs-markdown ol ol,
.cnblogs-markdown ul ol {
list-style-type: lower-roman;
}

.cnblogs-markdown ul ul ol,
.cnblogs-markdown ul ol ol,
.cnblogs-markdown ol ul ol,
.cnblogs-markdown ol ol ol {
list-style-type: lower-alpha;
}

.cnblogs-markdown dd {
margin-left: 0;
}

.cnblogs-markdown code {
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 12px;
}

.cnblogs-markdown pre {
margin-top: 0;
margin-bottom: 0;
font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

.cnblogs-markdown .octicon {
font: normal normal normal 16px/1 octicons-anchor;
display: inline-block;
text-decoration: none;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

.cnblogs-markdown .octicon-link:before {
content: '\f05c';
}

.cnblogs-markdown>*:first-child {
margin-top: 0 !important;
}

.cnblogs-markdown>*:last-child {
margin-bottom: 0 !important;
}

.cnblogs-markdown a:not(:link):not(:visited) {
color: inherit;
text-decoration: none;
}

.cnblogs-markdown .anchor {
position: absolute;
top: 0;
left: 0;
display: block;
padding-right: 6px;
padding-left: 30px;
margin-left: -30px;
}

.cnblogs-markdown .anchor:focus {
outline: none;
}

.cnblogs-markdown h1,
.cnblogs-markdown h2,
.cnblogs-markdown h3,
.cnblogs-markdown h4,
.cnblogs-markdown h5,
.cnblogs-markdown h6 {
position: relative;
margin-top: 1em;
margin-bottom: 16px;
font-weight: bold;
line-height: 1.4;
}

.cnblogs-markdown h1 .octicon-link,
.cnblogs-markdown h2 .octicon-link,
.cnblogs-markdown h3 .octicon-link,
.cnblogs-markdown h4 .octicon-link,
.cnblogs-markdown h5 .octicon-link,
.cnblogs-markdown h6 .octicon-link {
display: none;
color: #000;
vertical-align: middle;
}

.cnblogs-markdown h1:hover .anchor,
.cnblogs-markdown h2:hover .anchor,
.cnblogs-markdown h3:hover .anchor,
.cnblogs-markdown h4:hover .anchor,
.cnblogs-markdown h5:hover .anchor,
.cnblogs-markdown h6:hover .anchor {
padding-left: 8px;
margin-left: -30px;
text-decoration: none;
}

.cnblogs-markdown h1:hover .anchor .octicon-link,
.cnblogs-markdown h2:hover .anchor .octicon-link,
.cnblogs-markdown h3:hover .anchor .octicon-link,
.cnblogs-markdown h4:hover .anchor .octicon-link,
.cnblogs-markdown h5:hover .anchor .octicon-link,
.cnblogs-markdown h6:hover .anchor .octicon-link {
display: inline-block;
}

.cnblogs-markdown h1 {
padding-bottom: 0.3em;
font-size: 2.25em !important;
line-height: 1.2;
border-bottom: 1px solid #eee;
}

.cnblogs-markdown h1 .anchor {
line-height: 1;
}

.cnblogs-markdown h2 {
padding-bottom: 0.3em;
font-size: 1.75em !important;
line-height: 1.225;
border-bottom: 1px solid #eee;
}

.cnblogs-markdown h2 .anchor {
line-height: 1;
}

.cnblogs-markdown h3 {
font-size: 1.5em!important;
line-height: 1.43;
}

.cnblogs-markdown h3 .anchor {
line-height: 1.2;
}

.cnblogs-markdown h4 {
font-size: 1.25em !important;
}

.cnblogs-markdown h4 .anchor {
line-height: 1.2;
}

.cnblogs-markdown h5 {
font-size: 1em !important;
}

.cnblogs-markdown h5 .anchor {
line-height: 1.1;
}

.cnblogs-markdown h6 {
font-size: 1em !important;
color: #777;
}

.cnblogs-markdown h6 .anchor {
line-height: 1.1;
}

.cnblogs-markdown p,
.cnblogs-markdown blockquote,
.cnblogs-markdown ul,
.cnblogs-markdown ol,
.cnblogs-markdown dl,
.cnblogs-markdown table,
.cnblogs-markdown pre {
margin-top: 0;
margin-bottom: 16px;
}

.cnblogs-markdown hr {
height: 4px;
padding: 0;
margin: 16px 0;
background-color: #e7e7e7;
border: 0 none;
}

.cnblogs-markdown ul,
.cnblogs-markdown ol {
padding-left: 2em;
font-size: 14px;
}

.cnblogs-markdown ul ul,
.cnblogs-markdown ul ol,
.cnblogs-markdown ol ol,
.cnblogs-markdown ol ul {
margin-top: 0;
margin-bottom: 0;
}

.cnblogs-markdown li>p {
margin-top: 16px;
}

.cnblogs-markdown dl {
padding: 0;
}

.cnblogs-markdown dl dt {
padding: 0;
margin-top: 16px;
font-size: 1em;
font-style: italic;
font-weight: bold;
}

.cnblogs-markdown dl dd {
padding: 0 16px;
margin-bottom: 16px;
}

.cnblogs-markdown blockquote {
color: #333;
padding: 10px 15px;
border: none;
border-left: 10px solid #D6DBDF;
}

.cnblogs-markdown blockquote>:first-child {
margin-top: 0;
}

.cnblogs-markdown blockquote>:last-child {
margin-bottom: 0;
}

.cnblogs-markdown table {
display: block;
width: 100%;
overflow: auto;
word-break: normal;
word-break: keep-all;
}

.cnblogs-markdown table th {
font-weight: bold;
}

.cnblogs-markdown table th,
.cnblogs-markdown table td {
padding: 6px 13px;
border: 1px solid #ddd;
}

.cnblogs-markdown table tr {
background-color: #fff;
border-top: 1px solid #ccc;
}

.cnblogs-markdown table tr:nth-child(2n) {
background-color: #f8f8f8;
}

.cnblogs-markdown img {
max-width: 100%;
box-sizing: border-box;
}

.cnblogs-markdown code {
padding: 0;
padding-top: 0.2em;
padding-bottom: 0.2em;
margin: 0;
font-size: 85%;
background-color: rgba(0,0,0,0.04);
border-radius: 3px;
border: none !important;
display: inline-block;
}

.cnblogs-markdown code:before,
.cnblogs-markdown code:after {
letter-spacing: -0.2em;
content: "\00a0";
}

/*only for syntaxhighlighter */
/*--start--*/
.cnblogs-markdown .syntaxhighlighter table td.code {
width:95% !important;
}

.cnblogs-markdown .syntaxhighlighter code {
font-family: "Consolas","Bitstream Vera Sans Mono","Courier New",Courier,monospace!important;
padding: 0 !important;
border-radius: 0 !important;
background-color: transparent !important;
}

.cnblogs-markdown .syntaxhighlighter code:before,
.cnblogs-markdown .syntaxhighlighter code:before {
letter-spacing: -0.5em;
}
/*--end--*/

.cnblogs-markdown pre>code {
padding: 0;
margin: 0;
font-size: 100%;
word-break: normal;
white-space: pre;
background: transparent;
border: 0;
}

.cnblogs-markdown .highlight {
margin-bottom: 16px;
}

.cnblogs-markdown .highlight pre,
.cnblogs-markdown pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border-radius: 3px;
}

.cnblogs-markdown .highlight pre {
margin-bottom: 0;
word-break: normal;
}

.cnblogs-markdown pre {
word-wrap: normal;
}

.cnblogs-markdown pre code {
display: inline;
max-width: initial;
padding: 0;
margin: 0;
overflow: initial;
line-height: inherit;
word-wrap: normal;
background-color: transparent;
border: 0;
}

.cnblogs-markdown pre code:before,
.cnblogs-markdown pre code:after {
content: normal;
}

.cnblogs-markdown kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}

.cnblogs-markdown .pl-c {
color: #969896;
}

.cnblogs-markdown .pl-c1,
.cnblogs-markdown .pl-mdh,
.cnblogs-markdown .pl-mm,
.cnblogs-markdown .pl-mp,
.cnblogs-markdown .pl-mr,
.cnblogs-markdown .pl-s1 .pl-v,
.cnblogs-markdown .pl-s3,
.cnblogs-markdown .pl-sc,
.cnblogs-markdown .pl-sv {
color: #0086b3;
}

.cnblogs-markdown .pl-e,
.cnblogs-markdown .pl-en {
color: #795da3;
}

.cnblogs-markdown .pl-s1 .pl-s2,
.cnblogs-markdown .pl-smi,
.cnblogs-markdown .pl-smp,
.cnblogs-markdown .pl-stj,
.cnblogs-markdown .pl-vo,
.cnblogs-markdown .pl-vpf {
color: #333;
}

.cnblogs-markdown .pl-ent {
color: #63a35c;
}

.cnblogs-markdown .pl-k,
.cnblogs-markdown .pl-s,
.cnblogs-markdown .pl-st {
color: #a71d5d;
}

.cnblogs-markdown .pl-pds,
.cnblogs-markdown .pl-s1,
.cnblogs-markdown .pl-s1 .pl-pse .pl-s2,
.cnblogs-markdown .pl-sr,
.cnblogs-markdown .pl-sr .pl-cce,
.cnblogs-markdown .pl-sr .pl-sra,
.cnblogs-markdown .pl-sr .pl-sre,
.cnblogs-markdown .pl-src {
color: #183691;
}

.cnblogs-markdown .pl-v {
color: #ed6a43;
}

.cnblogs-markdown .pl-id {
color: #b52a1d;
}

.cnblogs-markdown .pl-ii {
background-color: #b52a1d;
color: #f8f8f8;
}

.cnblogs-markdown .pl-sr .pl-cce {
color: #63a35c;
font-weight: bold;
}

.cnblogs-markdown .pl-ml {
color: #693a17;
}

.cnblogs-markdown .pl-mh,
.cnblogs-markdown .pl-mh .pl-en,
.cnblogs-markdown .pl-ms {
color: #1d3e81;
font-weight: bold;
}

.cnblogs-markdown .pl-mq {
color: #008080;
}

.cnblogs-markdown .pl-mi {
color: #333;
font-style: italic;
}

.cnblogs-markdown .pl-mb {
color: #333;
font-weight: bold;
}

.cnblogs-markdown .pl-md,
.cnblogs-markdown .pl-mdhf {
background-color: #ffecec;
color: #bd2c00;
}
.cnblogs-markdown .pl-mdht,
.cnblogs-markdown .pl-mi1 {
background-color: #eaffea;
color: #55a532;
}

.cnblogs-markdown .pl-mdr {
color: #795da3;
font-weight: bold;
}

.cnblogs-markdown .pl-mo {
color: #1d3e81;
}

.cnblogs-markdown kbd {
display: inline-block;
padding: 3px 5px;
font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
padding-top: 20px;
}

.cnblogs-markdown .task-list-item {
list-style-type: none;
}

.cnblogs-markdown .task-list-item+.task-list-item {
margin-top: 3px;
}

.cnblogs-markdown .task-list-item input {
margin: 0 0.35em 0.25em -1.6em;
vertical-align: middle;
}

.cnblogs-markdown :checked+.radio-label {
z-index: 1;
position: relative;
border-color: #4183c4;
}


.cnblogs-markdown .hljs {
border: none !important;
}
#cnblogs_post_body th, #cnblogs_post_body td, .cnblogs-post-body th, .cnblogs-post-body td {
border: none !important;
padding: 0;
}

.postCon {
font-size: 14px;
}

.cnblogs-markdown .hljs, .cnblogs-post-body .hljs {
line-height: 1.5!important;
padding: 5px!important;
}

#cnblogs_post_body table, .cnblogs-post-body table {
border: none !important;
border-collapse: collapse;
word-break: break-word;
}



/*搬家之后代码(即markdown)的格式*/

.cnblogs-markdown .hljs {
display: block !important;
overflow-x: auto !important;
padding: 0.5em !important;
background: #23241f !important;
color: white !important;
font-family: Consolas !important;
font-size: 16px !important;
letter-spacing: 1px !important;
}

.cnblogs-markdown .hljs,
.cnblogs-markdown .hljs-tag,
.cnblogs-markdown .hljs-subst {
color: #f8f8f2 !important;
}

.cnblogs-markdown .hljs-strong,
.cnblogs-markdown .hljs-emphasis {
color: #a8a8a2 !important;
}

.cnblogs-markdown .hljs-bullet,
.cnblogs-markdown .hljs-quote,
.cnblogs-markdown .hljs-number,
.cnblogs-markdown .hljs-regexp,
.cnblogs-markdown .hljs-literal,
.cnblogs-markdown .hljs-link {
color: #ae81ff !important;
}

.cnblogs-markdown .hljs-code,
.cnblogs-markdown .hljs-title,
.cnblogs-markdown .hljs-section,
.cnblogs-markdown .hljs-selector-class {
color: #a6e22e !important;
}

.cnblogs-markdown .hljs-strong {
font-weight: bold !important;
}

.cnblogs-markdown .hljs-emphasis {
font-style: italic !important;
}

.cnblogs-markdown .hljs-keyword,
.cnblogs-markdown .hljs-selector-tag,
.cnblogs-markdown .hljs-name,
.cnblogs-markdown .hljs-attr {
color: #f92672 !important;
}
.cnblogs-markdown .hljs-keyword,.cnblogs-markdown .hljs-built_in{
color: #f92672 !important; //for while 玫红色
}

.cnblogs-markdown .hljs-symbol,
.cnblogs-markdown .hljs-attribute {
color: #66d9ef !important;
}

.cnblogs-markdown .hljs-params,
.cnblogs-markdown .hljs-class .cnblogs-markdown .hljs-title {
color: #f8f8f2 !important;
}

.cnblogs-markdown .hljs-string,
.cnblogs-markdown .hljs-type,
.cnblogs-markdown .hljs-builtin-name,
.cnblogs-markdown .hljs-selector-id,
.cnblogs-markdown .hljs-selector-attr,
.cnblogs-markdown .hljs-selector-pseudo,
.cnblogs-markdown .hljs-addition,
.cnblogs-markdown .hljs-variable,
.cnblogs-markdown .hljs-template-variable {
color: #e6db74 !important;
}

.cnblogs-markdown .hljs-comment,
.cnblogs-markdown .hljs-deletion{
color: #75715e !important;
}

.cnblogs-markdown .hljs-meta{
color: #f92672 !important;
}

/*
搬家之前代码(即非markdown)的格式
*/

.hljs {
display: block !important;
overflow-x: auto !important;
padding: 0.5em !important;
background: #23241f !important;
color: white !important;
font-family: Consolas !important;
font-size: 16px !important;
letter-spacing: 1px !important;

word-break: break-word;
word-wrap: normal;
}

.hljs-tag,
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-strong,
.hljs-name {
color: #f92672;
}

.hljs-code {
color: #66d9ef;
}

.hljs-class .hljs-title {
color: white;
}

.hljs-attribute,
.hljs-symbol,
.hljs-regexp,
.hljs-link {
color: #bf79db;
}

.hljs-string,
.hljs-bullet,
.hljs-subst,
.hljs-title,
.hljs-section,
.hljs-emphasis,
.hljs-type,
.hljs-built_in,
.hljs-builtin-name,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #a6e22e;
}

.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
color: #75715e;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-doctag,
.hljs-title,
.hljs-section,
.hljs-type,
.hljs-selector-id {
font-weight: bold;
}

其中!important表示其优先级在同组中提升为最高,避免其余博客园自有代码发生冲突而无效,至于字体、大小、字符间距以及行间距都是可以调整的,查阅css语法即可。
添加行号通过调用highlightjs-line-numbers.js实现,注意只能使用1.1.0版本或更早的版本,1.1.0之后的版本把每行代码都用横线分割了,整个就像一个表格太丑了,如下所示:

可在”页脚 HTML 代码”栏添加如下代码:

1
2
3
4
5
6
7
8
9
<script src="//cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@1.1.0/dist/highlightjs-line-numbers.min.js"></script>

<script>
$(function () {
/* markdown模式下为代码加入行号, 调用插件highlightjs-line-numbers.js */
hljs.initHighlightingOnLoad();
hljs.initLineNumbersOnLoad();
});
</script>

但是仅添加highlightjs-line-numbers.js是不够的,因为若某行代码过长则会造成行号显示错位,如下图所示:

通过参考博客园markdown显示行号探索心路历程,发现可以通过设置css的overflow-x参数使得代码过长时自动添加滚动条是的代码永远保持在同一行从而避免行号错位,但具体操作尚未完全搞清楚,只好把上述博主的代码全部copy过来,将其中.hljs中关于字体字号的设置删去以避免与我之前的设置产生冲突,发现搬家之后(即markdown)的代码行号错位的问题解决了,但是搬家之前(非markdown)的代码行号的错位问题仍未解决。

博客园中实现代码高亮
优化博客园Markdown样式(代码行号、版权信息、章节目录等)
博客园markdown显示行号探索心路历程
改进博客园Markdown显示功能(加代码行号、显示代码所用编程语言)

Copyright © 2019 - 2024 Jingwang Li

Powered by Hexo | Theme Hiker