From aeed92d50260d31e5f84b4e366bb55b1c2afcc27 Mon Sep 17 00:00:00 2001 From: zzhaobraze Date: Thu, 19 Dec 2024 13:14:40 -0500 Subject: [PATCH 1/2] normalize tab names better --- _plugins/tabs.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_plugins/tabs.rb b/_plugins/tabs.rb index adc273de945..3022649ebcd 100644 --- a/_plugins/tabs.rb +++ b/_plugins/tabs.rb @@ -14,11 +14,11 @@ def render(context) if tabs.length > 0 tabs.each_with_index do |tab, ind| # scan returns array of results, only care about first match - tabslist += '
  • ' + tab[0] + '
  • ' + "\n" + tabslist += '">' + tab[0] + '' + "\n" end end tabslist += '' + "\n" @@ -48,7 +48,7 @@ def render(context) content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super content = converter.convert(content) content = content.strip # Strip again to avoid "\n" - tabslug = @tab.gsub(' ', '-') + tabslug = @tab.gsub(/[^0-9a-z]/i, '-') '
    ' + content + "
    " end @@ -70,11 +70,11 @@ def render(context) if tabs.length > 0 tabs.each_with_index do |tab, ind| # scan returns array of results, only care about first match - tabslist += '
  • ' + tab[0] + '
  • ' + "\n" + tabslist += '">' + tab[0] + '' + "\n" end end tabslist += '' + "\n" From 7bf8c0bed97e44fc6a5ce6184ba2725000436a1b Mon Sep 17 00:00:00 2001 From: zzhaobraze Date: Thu, 19 Dec 2024 14:19:44 -0500 Subject: [PATCH 2/2] use md5 fallback --- _plugins/tabs.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/_plugins/tabs.rb b/_plugins/tabs.rb index 3022649ebcd..cea844897f7 100644 --- a/_plugins/tabs.rb +++ b/_plugins/tabs.rb @@ -1,3 +1,5 @@ +require 'digest/md5' + module Tags class TabsBlock < Liquid::Block def initialize(tag_name, tabonly = 'false', tokens) @@ -13,12 +15,15 @@ def render(context) tabslist = '' + "\n" @@ -48,7 +53,8 @@ def render(context) content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super content = converter.convert(content) content = content.strip # Strip again to avoid "\n" - tabslug = @tab.gsub(/[^0-9a-z]/i, '-') + tabslug = @tab.gsub(/[^0-9a-z]/i, '') + tabslug = Digest::MD5.hexdigest(@tab) if tabslug.empty? '
    ' + content + "
    " end @@ -66,15 +72,17 @@ def initialize(tag_name, tabonly = 'false', tokens) def render(context) tabs = super.scan(/data\-sub\_tab=\"(.*?)\"/) tabslist = '' + "\n" @@ -104,7 +112,8 @@ def render(context) content = indentation ? super.gsub(/^#{' |\t' * indentation}/, '') : super content = converter.convert(content) content = content.strip # Strip again to avoid "\n" - tabslug = @tab.gsub(' ', '-') + tabslug = @tab.gsub(/[^0-9a-z]/i, '') + tabslug = Digest::MD5.hexdigest(@tab) if tabslug.empty? '
    ' + content + "
    " end