Home > Software engineering >  No replacing dots on StringToSlug
No replacing dots on StringToSlug

Time:10-13

How would you not replace dots using String To Slug (http://leocaseiro.github.io/jQuery-Plugin-stringToSlug/). Currently if you use a dot on the string is replaced with a hyphen, but I would like for the slug to keep the dot, not to replace it.

Thanks!

CodePudding user response:

Debugged the issue with jQuery-Plugin-stringToSlug plugin. It was found that there is a getSlug( text, defaults.options ); function call happening from jquery.stringtoslug.js to getSlug method defined in speakingurl.js, which is a dependency of jquery.stringtoslug.js.

From the defenition of speakingurl, under the usage section, there is a property called mark defined. This additionally allow chars: "-", "_", ".", "!", "~", "*", "'", "(", ")". This is being fetched from options passed to getSlug method.

This options are passed from jquery.stringtoslug.js, which get its options from the function call stringToSlug

So you just have to set mark: true in your options.

Working Code

$(document).ready(function () {
  $(".basic-usage").stringToSlug({
    options: {
      mark: true
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/speakingurl/14.0.1/speakingurl.min.js"
  integrity="sha512-i1kgQZJBA3n0k1Ar2  6FKibz8fDlaDpZ8ZLKpCnypYznNL  R6FPxpKJP6NGwsO2sAzzX4x78XjiYrLtMWAfA=="
  crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="http://leocaseiro.github.io/jQuery-Plugin-stringToSlug/bower_components/jquery.stringtoslug/dist/jquery.stringtoslug.min.js"></script>

<input type="text" class="basic-usage" value="Replace the content of this input and check the preview text below!" />
<input type="text" id="permalink" />

  • Related