Skip to content

Commit

Permalink
moved html parser function to global section of story file
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcos Hernandez committed Oct 11, 2023
1 parent bf71ba2 commit 24efe19
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/app/(tabs)/search/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import HTMLView from 'react-native-htmlview';
import { SafeAreaView } from 'react-native-safe-area-context';
import globalStyles from '../../../styles/globalStyles';

function htmlParser(html: string) {
const regex = /<h2(.*?)h2>(\n+<p(.*?)p>)+/; // regex grabs heading and paragraph tags for story
const corresp = regex.exec(html);
const story = corresp ? corresp[0] : ''; // <h2>heading<h2> <p>paragraph1</p> ...
return story;
}

function StoryScreen() {
const [isLoading, setLoading] = useState(true);
const [title, setTitle] = useState(String);
Expand All @@ -23,13 +30,6 @@ function StoryScreen() {
}
};

const htmlParser = (html: string) => {
const regex = /<h2(.*?)h2>(\n+<p(.*?)p>)+/; // regex grabs heading and paragraph tags for story
const corresp = regex.exec(html);
const story = corresp ? corresp[0] : ''; // <h2>heading<h2> <p>paragraph1</p> ...
return story;
};

useEffect(() => {
getStory('170947');
}, []);
Expand Down

0 comments on commit 24efe19

Please sign in to comment.