Browse Source

feat: add include tags option in the get text block

Ahmad Kholid 3 years ago
parent
commit
779afa1c06

+ 11 - 7
src/components/newtab/workflow/edit/EditGetText.vue

@@ -1,6 +1,6 @@
 <template>
   <edit-interaction-base v-bind="{ data }" @change="updateData">
-    <div class="flex rounded-lg bg-input px-4 items-center transition mt-2">
+    <div class="flex rounded-lg bg-input px-4 items-center transition mt-3">
       <span>/</span>
       <input
         :value="data.regex"
@@ -69,6 +69,13 @@
       class="w-full"
       @change="updateData({ suffixText: $event })"
     />
+    <ui-checkbox
+      :model-value="data.includeTags"
+      class="mt-3"
+      @change="updateData({ includeTags: $event })"
+    >
+      {{ t('workflow.blocks.get-text.includeTags') }}
+    </ui-checkbox>
     <ui-checkbox
       :model-value="data.addExtraRow"
       class="mt-3"
@@ -125,7 +132,7 @@ const emit = defineEmits(['update:data']);
 const { t } = useI18n();
 
 const workflow = inject('workflow');
-const regexExp = ref(props.data.regexExp);
+const regexExp = ref([...new Set(props.data.regexExp)]);
 
 const exps = [
   { id: 'g', name: 'global' },
@@ -137,15 +144,12 @@ function updateData(value) {
   emit('update:data', { ...props.data, ...value });
 }
 function handleExpCheckbox(id, value) {
-  const copy = [...new Set(regexExp.value)];
-
   if (value) {
-    copy.push(id);
+    regexExp.value.push(id);
   } else {
-    copy.splice(copy.indexOf(id), 1);
+    regexExp.value.splice(regexExp.value.indexOf(id), 1);
   }
 
-  regexExp.value = copy;
   updateData({ regexExp: regexExp.value });
 }
 </script>

+ 2 - 1
src/content/blocks-handler/handler-get-text.js

@@ -10,6 +10,7 @@ function getText(block) {
       prefixText,
       suffixText,
       multiple,
+      includeTags,
     } = block.data;
 
     if (regexData) {
@@ -18,7 +19,7 @@ function getText(block) {
 
     handleElement(block, {
       onSelected(element) {
-        let text = element.innerText;
+        let text = includeTags ? element.outerHTML : element.innerText;
 
         if (regex) text = text.match(regex).join(' ');
 

+ 1 - 0
src/locales/en/blocks.json

@@ -187,6 +187,7 @@
         "name": "Get text",
         "description": "Get text from an element",
         "checkbox": "Save data",
+        "includeTags": "Include HTML tags",
         "prefixText": {
           "placeholder": "Text prefix",
           "title": "Add prefix to the text"